bool APP_CC xrdp_emt_bw_check_stop(struct xrdp_rdp* self, int time_processing) { struct xrdp_emt* emt = self->sec_layer->chan_layer->emt_channel; int current_time = g_time3(); bool res; if (emt == NULL || !emt->activated) { return false; } if (emt->state != check_bw) { emt->time_processing+=time_processing; return true; } emt->time_processing = 0; emt->next_check = current_time + self->client_info.network_detection_interval; emt->state = wait_next_mesure; res = xrdp_emt_send_request(self, emt, RDP_BW_SESSION_STOP); emt->stop_time = g_time3(); if (emt->need_result && self->session->bandwidth > 0) { xrdp_emt_send_result(self, emt); emt->need_result = false; } return res; }
bool APP_CC xrdp_emt_process(struct xrdp_rdp* self, struct stream* s) { int sequenceNumber; int requestType; unsigned int current_time = g_time3(); struct xrdp_emt* emt = self->sec_layer->chan_layer->emt_channel; in_uint8s(s, 1); // headerLength in_uint8s(s, 1); // headerTypeId in_uint16_le(s, sequenceNumber); // sequenceNumber in_uint16_le(s, requestType); // requestType switch (requestType) { case RDP_RTT_RESPONSE_TYPE: emt->state = ready; break; case RDP_BW_RESULTS: xrdp_emt_process_results(self, emt, s); break; default: printf("Unknow request type: 0x%x", requestType); return false; } return true; }
bool APP_CC xrdp_emt_bw_check_start(struct xrdp_rdp* self) { struct xrdp_emt* emt = self->sec_layer->chan_layer->emt_channel; int current_time = g_time3(); if (emt == NULL || !emt->activated) { return false; } if (emt->state == wait_next_mesure) { if (current_time > emt->next_check) { emt->state = ready; } else { return true; } } if (emt->state != ready) { return true; } emt->state = check_bw; emt->time_processing = 0; return xrdp_emt_send_request(self, emt, RDP_BW_SESSION_START); }
void progressive_display_update_level(struct xrdp_screen* self, long *t0) { struct list* p_display = self->update_rects; int i; if ((g_time3() - *t0) > 1000) { for (i = 0; i < p_display->count; i++) { struct update_rect* cur = (struct update_rect*) list_get_item(p_display, i); if (cur->quality > 0) { cur->quality--; } } *t0 = g_time3(); } }
void APP_CC xrdp_emt_process_results(struct xrdp_rdp* self, struct xrdp_emt* emt, struct stream* s) { int time_delta; int byte_count; int current_time = g_time3(); int current_rtt = current_time - emt->stop_time; in_uint32_le(s, time_delta); in_uint32_le(s, byte_count); emt->total_delta += time_delta; emt->total_byte_count += byte_count; if (emt->total_byte_count > LONG_MAX) { emt->total_byte_count = emt->total_byte_count / emt->total_delta; emt->total_delta = 1; } if (byte_count > 1000) { if (emt->total_delta == 0) { self->session->bandwidth = byte_count / 0.9; } else { self->session->bandwidth = emt->total_byte_count/emt->total_delta; // Ko/s } } if (emt->time_processing < 2) { if (self->session->base_RTT > current_rtt) { self->session->base_RTT = current_rtt; } if (self->session->average_RTT == 0) { self->session->average_RTT = current_rtt; } else { self->session->average_RTT = (self->session->average_RTT + current_rtt) / 2; } } printf("bandwidth: %i Ko/s\n", self->session->bandwidth); printf("base RTT: %i ms\n", self->session->base_RTT); printf("average RTT: %i ms\n", self->session->average_RTT); self->session->network_stat_updated = true; }
static int APP_CC check_timeout(void) { struct timeout_obj *tobj; struct timeout_obj *last_tobj; struct timeout_obj *temp_tobj; int count; tui32 now; LOG(10, ("check_timeout:")); count = 0; tobj = g_timeout_head; if (tobj != 0) { last_tobj = 0; while (tobj != 0) { count++; now = g_time3(); if (now >= tobj->mstime) { tobj->callback(tobj->data); if (last_tobj == 0) { g_timeout_head = tobj->next; if (g_timeout_head == 0) { g_timeout_tail = 0; } } else { last_tobj->next = tobj->next; if (g_timeout_tail == tobj) { g_timeout_tail = last_tobj; } } temp_tobj = tobj; tobj = tobj->next; g_free(temp_tobj); } else { last_tobj = tobj; tobj = tobj->next; } } } LOG(10, (" count %d", count)); return 0; }
static int APP_CC get_timeout(int *timeout) { struct timeout_obj *tobj; tui32 now; int ltimeout; LOG(10, ("get_timeout:")); ltimeout = *timeout; if (ltimeout < 1) { ltimeout = 0; } tobj = g_timeout_head; if (tobj != 0) { now = g_time3(); while (tobj != 0) { LOG(10, (" now %u tobj->mstime %u", now, tobj->mstime)); if (now < tobj->mstime) { ltimeout = tobj->mstime - now; } tobj = tobj->next; } } if (ltimeout > 0) { LOG(10, (" ltimeout %d", ltimeout)); if (*timeout < 1) { *timeout = ltimeout; } else { if (*timeout > ltimeout) { *timeout = ltimeout; } } } return 0; }
int APP_CC add_timeout(int msoffset, void (*callback)(void *data), void *data) { struct timeout_obj *tobj; tui32 now; LOG(10, ("add_timeout:")); now = g_time3(); tobj = g_malloc(sizeof(struct timeout_obj), 1); tobj->mstime = now + msoffset; tobj->callback = callback; tobj->data = data; if (g_timeout_tail == 0) { g_timeout_head = tobj; g_timeout_tail = tobj; } else { g_timeout_tail->next = tobj; g_timeout_tail = tobj; } return 0; }
int APP_CC trans_connect(struct trans *self, const char *server, const char *port, int timeout) { int error; int now; int start_time; start_time = g_time3(); if (self->sck != 0) { g_tcp_close(self->sck); self->sck = 0; } if (self->mode == TRANS_MODE_TCP) /* tcp */ { self->sck = g_tcp_socket(); if (self->sck < 0) { self->status = TRANS_STATUS_DOWN; return 1; } g_tcp_set_non_blocking(self->sck); while (1) { error = g_tcp_connect(self->sck, server, port); if (error == 0) { break; } else { if (timeout < 1) { self->status = TRANS_STATUS_DOWN; return 1; } now = g_time3(); if (now - start_time < timeout) { g_sleep(timeout / 5); } else { self->status = TRANS_STATUS_DOWN; return 1; } } } } else if (self->mode == TRANS_MODE_UNIX) /* unix socket */ { self->sck = g_tcp_local_socket(); if (self->sck < 0) { self->status = TRANS_STATUS_DOWN; return 1; } g_tcp_set_non_blocking(self->sck); while (1) { error = g_tcp_local_connect(self->sck, port); if (error == 0) { break; } else { if (timeout < 1) { self->status = TRANS_STATUS_DOWN; return 1; } now = g_time3(); if (now - start_time < timeout) { g_sleep(timeout / 5); } else { self->status = TRANS_STATUS_DOWN; return 1; } } } } else { self->status = TRANS_STATUS_DOWN; return 1; } if (error == -1) { if (g_tcp_last_error_would_block(self->sck)) { now = g_time3(); if (now - start_time < timeout) { timeout = timeout - (now - start_time); } else { timeout = 0; } if (g_tcp_can_send(self->sck, timeout)) { self->status = TRANS_STATUS_UP; /* ok */ self->type1 = TRANS_TYPE_CLIENT; /* client */ return 0; } } return 1; } self->status = TRANS_STATUS_UP; /* ok */ self->type1 = TRANS_TYPE_CLIENT; /* client */ return 0; }
/* returns time in miliseconds this is like g_time2 in os_calls, but not miliseconds since machine was up, something else this is a time value similar to what the xserver uses */ int APP_CC xcommon_get_local_time(void) { return g_time3(); }
void DEFAULT_CC scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s) { int display = 0; tbus data; struct session_item* s_item; tc_mutex_lock(session_creation_lock); data = auth_userpass(NULL, s->username, s->password); #ifdef CHECK_PREMIUM_EDITION bool valid = true; if (get_module_version(get_module_name()) & PREMIUM_EDITION) { printf("%s %i %i %i \n", __FUNCTION__, g_time3(), last_time_premium_edition_check, CHECK_INTERVAL); if (((g_time3() - last_time_premium_edition_check) > CHECK_INTERVAL) || last_time_premium_edition_check == 0) { printf("%s FOFOFOOF\n", __FUNCTION__); valid = check_premium_edition(); } } if (!valid) { data = 0; scp_v0s_deny_connection(c, "Unable to launch the session\nInvalid License\nPlease contact your administrator\n"); tc_mutex_unlock(session_creation_lock); return; } #endif if (data == 0) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s failed to authenticate", s->username); scp_v0s_deny_connection(c, "Your username or \nyour password is invalid"); tc_mutex_unlock(session_creation_lock); return; } lock_chain_acquire(); s_item = session_get_bydata(s->username); lock_chain_release(); if (s_item != 0) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "A session for User %s already exist", s->username); display = s_item->display; if (s_item->status == SESMAN_SESSION_STATUS_TO_DESTROY) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "Session for user %s is in destroy, unable to initialize a new session", s->username); scp_v0s_deny_connection(c, "Your last session is currently \nended, retry later"); } else { session_update_status_by_user(s_item->name, SESMAN_SESSION_STATUS_ACTIVE); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "switch from status DISCONNECTED to ACTIVE"); session_switch_resolution(s->width, s->height, display); session_add_client_pid(s_item->name, s->client_pid); scp_v0s_allow_connection(c, display); } auth_end(data); tc_mutex_unlock(session_creation_lock); return; } log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "No session already started for the user %s", s->username); if (access_login_allowed(s->username) == 0) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s is not allow to start session", s->username); display = 0; scp_v0s_deny_connection(c, "You are not allowed\nto start a session\n"); auth_end(data); tc_mutex_unlock(session_creation_lock); return; } log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username); if (SCP_SESSION_TYPE_XVNC == s->type) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session for the user %s ...", s->username); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XVNC, s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim); } else { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session for the user %s ...", s->username); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XRDP, s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim); } auth_end(data); if (display == 0) { data = 0; scp_v0s_deny_connection(c, "Unable to launch the session\nPlease contact\nyour administrator\n"); } else { scp_v0s_allow_connection(c, display); } tc_mutex_unlock(session_creation_lock); }