diff --git a/xrdp/xrdp_login_wnd.c b/xrdp/xrdp_login_wnd.c index e8b43cc1..ee71008f 100644 --- a/xrdp/xrdp_login_wnd.c +++ b/xrdp/xrdp_login_wnd.c @@ -89,148 +89,8 @@ xrdp_wm_popup_notify(struct xrdp_bitmap* wnd, } #endif -/*****************************************************************************/ -/* called from main thread */ -static long DEFAULT_CC -sync_unload(long param1, long param2) -{ - return g_free_library(param1); -} - -/*****************************************************************************/ -/* called from main thread */ -static long DEFAULT_CC -sync_load(long param1, long param2) -{ - return g_load_library((char*)param1); -} - -/*****************************************************************************/ -int APP_CC -xrdp_wm_setup_mod1(struct xrdp_wm* self, - struct xrdp_mod_data* mod_data) -{ - void* func; - - if (self == 0) - { - return 1; - } - if (self->mod_handle == 0) - { - self->mod_handle = g_xrdp_sync(sync_load, (long)mod_data->lib, 0); - if (self->mod_handle != 0) - { - func = g_get_proc_address(self->mod_handle, "mod_init"); - if (func == 0) - { - func = g_get_proc_address(self->mod_handle, "_mod_init"); - } - if (func == 0) - { - g_writeln("error finding proc mod_init in %s", mod_data->lib); - } - self->mod_init = (struct xrdp_mod* (*)(void))func; - func = g_get_proc_address(self->mod_handle, "mod_exit"); - if (func == 0) - { - func = g_get_proc_address(self->mod_handle, "_mod_exit"); - } - if (func == 0) - { - g_writeln("error finding proc mod_exit in %s", mod_data->lib); - } - self->mod_exit = (int (*)(struct xrdp_mod*))func; - if (self->mod_init != 0 && self->mod_exit != 0) - { - self->mod = self->mod_init(); - } - } - else - { - g_writeln("error loading %s", mod_data->lib); - } - if (self->mod != 0) - { - self->mod->wm = (long)self; - self->mod->server_begin_update = server_begin_update; - self->mod->server_end_update = server_end_update; - self->mod->server_fill_rect = server_fill_rect; - self->mod->server_screen_blt = server_screen_blt; - self->mod->server_paint_rect = server_paint_rect; - self->mod->server_set_pointer = server_set_pointer; - self->mod->server_palette = server_palette; - self->mod->server_msg = server_msg; - self->mod->server_is_term = server_is_term; - self->mod->server_set_clip = server_set_clip; - self->mod->server_reset_clip = server_reset_clip; - self->mod->server_set_fgcolor = server_set_fgcolor; - self->mod->server_set_bgcolor = server_set_bgcolor; - self->mod->server_set_opcode = server_set_opcode; - self->mod->server_set_mixmode = server_set_mixmode; - self->mod->server_set_brush = server_set_brush; - self->mod->server_set_pen = server_set_pen; - self->mod->server_draw_line = server_draw_line; - self->mod->server_add_char = server_add_char; - self->mod->server_draw_text = server_draw_text; - self->mod->server_reset = server_reset; - self->mod->server_query_channel = server_query_channel; - self->mod->server_get_channel_id = server_get_channel_id; - self->mod->server_send_to_channel = server_send_to_channel; - } - } - /* id self->mod is null, there must be a problem */ - if (self->mod == 0) - { - DEBUG(("problem loading lib in xrdp_wm_setup_mod1")); - return 1; - } - return 0; -} - /*****************************************************************************/ int APP_CC -xrdp_wm_setup_mod2(struct xrdp_wm* self, - struct list* names, - struct list* values) -{ - char text[256]; - int i; - int rv; - - rv = 1; - if (!self->pro_layer->term) - { - if (self->mod->mod_start(self->mod, self->screen->width, - self->screen->height, self->screen->bpp) != 0) - { - self->pro_layer->term = 1; /* kill session */ - } - } - if (!self->pro_layer->term) - { - /* always set these */ - self->mod->mod_set_param(self->mod, "hostname", - self->session->client_info->hostname); - g_sprintf(text, "%d", self->session->client_info->keylayout); - self->mod->mod_set_param(self->mod, "keylayout", text); - for (i = 0; i < names->count; i++) - { - self->mod->mod_set_param(self->mod, - (char*)list_get_item(names, i), - (char*)list_get_item(values, i)); - } - /* connect */ - if (self->mod->mod_connect(self->mod) == 0) - { - rv = 0; - } - } - return rv; -} - -/*****************************************************************************/ -static int APP_CC xrdp_wm_delete_all_childs(struct xrdp_wm* self) { int i; @@ -326,8 +186,6 @@ xrdp_wm_ok_clicked(struct xrdp_bitmap* wnd) struct xrdp_bitmap* label; struct xrdp_bitmap* edit; struct xrdp_wm* wm; - struct list* names; - struct list* values; struct xrdp_mod_data* mod_data; int i; @@ -350,57 +208,18 @@ xrdp_wm_ok_clicked(struct xrdp_bitmap* wnd) label = xrdp_bitmap_get_child_by_id(wnd, i); edit = xrdp_bitmap_get_child_by_id(wnd, i + 1); } - if (xrdp_wm_setup_mod1(wm, mod_data) == 0) - { - /* gota copy these cause dialog gets freed */ - names = list_create(); - names->auto_free = 1; - for (i = 0; i < mod_data->names->count; i++) - { - list_add_item(names, - (long)g_strdup((char*)list_get_item(mod_data->names, i))); - } - values = list_create(); - values->auto_free = 1; - for (i = 0; i < mod_data->values->count; i++) - { - list_add_item(values, - (long)g_strdup((char*)list_get_item(mod_data->values, i))); - } - xrdp_wm_delete_all_childs(wm); - if (xrdp_wm_setup_mod2(wm, names, values) != 0) - { - /* totaly free mod */ - if (wm->mod_exit != 0) - { - wm->mod_exit(wm->mod); - } - g_xrdp_sync(sync_unload, wm->mod_handle, 0); - wm->mod = 0; - wm->mod_handle = 0; - wm->mod_init = 0; - wm->mod_exit = 0; - } - else /* close connection log window if connection is ok */ - { - if (wm->log_wnd != 0) - { - xrdp_bitmap_delete(wm->log_wnd); - } - } - if (!wm->pro_layer->term) - { - if (wm->mod != 0) - { - if (wm->mod->sck != 0) - { - wm->pro_layer->app_sck = wm->mod->sck; - } - } - } - list_delete(names); - list_delete(values); - } + list_delete(wm->mm->login_names); + list_delete(wm->mm->login_values); + wm->mm->login_names = list_create(); + wm->mm->login_names->auto_free = 1; + wm->mm->login_values = list_create(); + wm->mm->login_values->auto_free = 1; + /* gota copy these cause dialog gets freed */ + list_append_list_strdup(mod_data->names, wm->mm->login_names, 0); + list_append_list_strdup(mod_data->values, wm->mm->login_values, 0); + list_add_item(wm->mm->login_names, (long)g_strdup("lib")); + list_add_item(wm->mm->login_values, (long)g_strdup(mod_data->lib)); + wm->login_mode = 2; } } return 0; diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index 19e2e381..bff8b004 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -44,18 +44,10 @@ xrdp_wm_create(struct xrdp_process* owner, self->log->auto_free = 1; self->key_down_list = list_create(); self->key_down_list->auto_free = 1; + self->mm = xrdp_mm_create(self); return self; } -/*****************************************************************************/ -/* called from main thread */ -static long DEFAULT_CC -sync_unload(long param1, long param2) -{ - g_free_library(param1); - return 0; -} - /*****************************************************************************/ void APP_CC xrdp_wm_delete(struct xrdp_wm* self) @@ -64,21 +56,10 @@ xrdp_wm_delete(struct xrdp_wm* self) { return; } + xrdp_mm_delete(self->mm); xrdp_cache_delete(self->cache); xrdp_painter_delete(self->painter); xrdp_bitmap_delete(self->screen); - /* free any modual stuff */ - if (self->mod != 0) - { - if (self->mod_exit != 0) - { - self->mod_exit(self->mod); - } - } - if (self->mod_handle != 0) - { - g_xrdp_sync(sync_unload, self->mod_handle, 0); - } /* free the log */ list_delete(self->log); /* key down list */ @@ -361,6 +342,7 @@ xrdp_wm_load_static_pointers(struct xrdp_wm* self) int APP_CC xrdp_wm_init(struct xrdp_wm* self) { +#if 0 int fd; int index; struct xrdp_mod_data* mod_data; @@ -369,10 +351,13 @@ xrdp_wm_init(struct xrdp_wm* self) char* q; char* r; char section_name[256]; +#endif xrdp_wm_load_static_colors(self); xrdp_wm_load_static_pointers(self); self->screen->bg_color = self->black; +#if 0 + // todo, get autologin working if (self->session->client_info->rdp_autologin) { fd = g_file_open(XRDP_CFG_FILE); /* xrdp.ini */ @@ -494,6 +479,7 @@ xrdp_wm_init(struct xrdp_wm* self) } } else +#endif { xrdp_login_wnd_create(self); /* clear screen */ @@ -797,11 +783,11 @@ xrdp_wm_mouse_move(struct xrdp_wm* self, int x, int y) xrdp_wm_set_pointer(self, self->screen->pointer); self->current_pointer = self->screen->pointer; } - if (self->mod != 0) /* if screen is mod controled */ + if (self->mm->mod != 0) /* if screen is mod controled */ { - if (self->mod->mod_event != 0) + if (self->mm->mod->mod_event != 0) { - self->mod->mod_event(self->mod, WM_MOUSEMOVE, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_MOUSEMOVE, x, y, 0, 0); } } } @@ -920,47 +906,47 @@ xrdp_wm_mouse_click(struct xrdp_wm* self, int x, int y, int but, int down) control = xrdp_wm_at_pos(self->screen, x, y, &wnd); if (control == 0) { - if (self->mod != 0) /* if screen is mod controled */ + if (self->mm->mod != 0) /* if screen is mod controled */ { - if (self->mod->mod_event != 0) + if (self->mm->mod->mod_event != 0) { if (but == 1 && down) { - self->mod->mod_event(self->mod, WM_LBUTTONDOWN, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_LBUTTONDOWN, x, y, 0, 0); } else if (but == 1 && !down) { - self->mod->mod_event(self->mod, WM_LBUTTONUP, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_LBUTTONUP, x, y, 0, 0); } if (but == 2 && down) { - self->mod->mod_event(self->mod, WM_RBUTTONDOWN, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_RBUTTONDOWN, x, y, 0, 0); } else if (but == 2 && !down) { - self->mod->mod_event(self->mod, WM_RBUTTONUP, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_RBUTTONUP, x, y, 0, 0); } if (but == 3 && down) { - self->mod->mod_event(self->mod, WM_BUTTON3DOWN, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_BUTTON3DOWN, x, y, 0, 0); } else if (but == 3 && !down) { - self->mod->mod_event(self->mod, WM_BUTTON3UP, x, y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_BUTTON3UP, x, y, 0, 0); } if (but == 4) { - self->mod->mod_event(self->mod, WM_BUTTON4DOWN, - self->mouse_x, self->mouse_y, 0, 0); - self->mod->mod_event(self->mod, WM_BUTTON4UP, - self->mouse_x, self->mouse_y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_BUTTON4DOWN, + self->mouse_x, self->mouse_y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_BUTTON4UP, + self->mouse_x, self->mouse_y, 0, 0); } if (but == 5) { - self->mod->mod_event(self->mod, WM_BUTTON5DOWN, - self->mouse_x, self->mouse_y, 0, 0); - self->mod->mod_event(self->mod, WM_BUTTON5UP, - self->mouse_x, self->mouse_y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_BUTTON5DOWN, + self->mouse_x, self->mouse_y, 0, 0); + self->mm->mod->mod_event(self->mm->mod, WM_BUTTON5UP, + self->mouse_x, self->mouse_y, 0, 0); } } } @@ -1160,9 +1146,9 @@ xrdp_wm_key(struct xrdp_wm* self, int device_flags, int scan_code) break; /* scroll lock */ } } - if (self->mod != 0) + if (self->mm->mod != 0) { - if (self->mod->mod_event != 0) + if (self->mm->mod->mod_event != 0) { if (msg == WM_KEYDOWN) { @@ -1173,15 +1159,15 @@ xrdp_wm_key(struct xrdp_wm* self, int device_flags, int scan_code) self->session->client_info->keylayout); if (c != 0) { - self->mod->mod_event(self->mod, msg, (unsigned char)c, 0xffff, - scan_code, device_flags); + self->mm->mod->mod_event(self->mm->mod, msg, (unsigned char)c, + 0xffff, scan_code, device_flags); xrdp_add_key_down(self, (unsigned char)c, 0xffff, scan_code, device_flags); } else { - self->mod->mod_event(self->mod, msg, scan_code, device_flags, - scan_code, device_flags); + self->mm->mod->mod_event(self->mm->mod, msg, scan_code, + device_flags, scan_code, device_flags); xrdp_add_key_down(self, scan_code, device_flags, scan_code, device_flags); } @@ -1190,10 +1176,10 @@ xrdp_wm_key(struct xrdp_wm* self, int device_flags, int scan_code) { if (key_down != 0) { - self->mod->mod_event(self->mod, msg, key_down->param1, - key_down->param2 | KBD_FLAG_UP, - key_down->scan_code, - key_down->param4 | KBD_FLAG_UP); + self->mm->mod->mod_event(self->mm->mod, msg, key_down->param1, + key_down->param2 | KBD_FLAG_UP, + key_down->scan_code, + key_down->param4 | KBD_FLAG_UP); list_remove_item(self->key_down_list, key_down_index); } } @@ -1227,12 +1213,12 @@ xrdp_wm_key_sync(struct xrdp_wm* self, int device_flags, int key_flags) { self->caps_lock = 1; } - if (self->mod != 0) + if (self->mm->mod != 0) { - if (self->mod->mod_event != 0) + if (self->mm->mod->mod_event != 0) { - self->mod->mod_event(self->mod, 17, key_flags, device_flags, - key_flags, device_flags); + self->mm->mod->mod_event(self->mm->mod, 17, key_flags, device_flags, + key_flags, device_flags); } } return 0; @@ -1330,12 +1316,12 @@ static int APP_CC xrdp_wm_process_channel_data(struct xrdp_wm* self, int channel_id, char* data, int data_len) { - if (self->mod != 0) + if (self->mm->mod != 0) { - if (self->mod->mod_event != 0) + if (self->mm->mod->mod_event != 0) { - self->mod->mod_event(self->mod, 0x5555, channel_id, (long)data, - data_len, 0); + self->mm->mod->mod_event(self->mm->mod, 0x5555, channel_id, (long)data, + data_len, 0); } } return 0; @@ -1384,3 +1370,161 @@ callback(long id, int msg, long param1, long param2, long param3, long param4) } return rv; } + +/******************************************************************************/ +/* returns error */ +/* this gets called when there is nothing on any socket */ +int APP_CC +xrdp_wm_idle(struct xrdp_wm* self) +{ + g_sleep(10); + if (self == 0) + { + return 0; + } + if (self->login_mode == 0) + { + /* this is the inital state of the login window */ + list_clear(self->log); + xrdp_wm_delete_all_childs(self); + if (xrdp_wm_init(self) == 0) + { + /* put the wm in login mode */ + self->login_mode = 1; + } + } + else if (self->login_mode == 2) + { + self->login_mode = 3; + xrdp_wm_delete_all_childs(self); + xrdp_mm_connect(self->mm); + } + return 0; +} + +/******************************************************************************/ +/* returns error */ +/* this gets called when there is nothing on any socket */ +int APP_CC +xrdp_wm_app_sck_signal(struct xrdp_wm* self, int app_sck) +{ + if (self->login_mode == 3) + { + if (xrdp_mm_signal(self->mm) != 0) + { + return 1; + } + } + else if (self->login_mode == 10) + { + if (self->mm->mod == 0) + { + return 1; + } + if (self->mm->mod->mod_signal == 0) + { + return 1; + } + if (self->mm->mod->mod_signal(self->mm->mod) != 0) + { + return 1; + } + } + return 0; +} + +/*****************************************************************************/ +/* this is the log windows nofity function */ +static int DEFAULT_CC +xrdp_wm_log_wnd_notify(struct xrdp_bitmap* wnd, + struct xrdp_bitmap* sender, + int msg, long param1, long param2) +{ + struct xrdp_painter* painter; + struct xrdp_wm* wm; + struct xrdp_rect rect; + int index; + char* text; + + if (wnd == 0) + { + return 0; + } + if (sender == 0) + { + return 0; + } + if (wnd->owner == 0) + { + return 0; + } + wm = wnd->wm; + if (msg == 1) /* click */ + { + if (sender->id == 1) /* ok button */ + { + /* close the log window */ + MAKERECT(rect, wnd->left, wnd->top, wnd->width, wnd->height); + xrdp_bitmap_delete(wnd); + xrdp_bitmap_invalidate(wm->screen, &rect); + /* if module is gone, end the session when ok is clicked */ + if (wm->mm->mod_handle == 0) + { + wm->login_mode = 0; /* reset session */ + } + } + } + else if (msg == WM_PAINT) /* 3 */ + { + painter = (struct xrdp_painter*)param1; + if (painter != 0) + { + painter->font->color = wnd->wm->black; + for (index = 0; index < wnd->wm->log->count; index++) + { + text = (char*)list_get_item(wnd->wm->log, index); + xrdp_painter_draw_text(painter, wnd, 10, 30 + index * 15, text); + } + } + } + return 0; +} + +/*****************************************************************************/ +int APP_CC +xrdp_wm_log_msg(struct xrdp_wm* self, char* msg) +{ + struct xrdp_bitmap* but; + + list_add_item(self->log, (long)g_strdup(msg)); + if (self->log_wnd == 0) + { + /* log window */ + self->log_wnd = xrdp_bitmap_create(400, 400, self->screen->bpp, + WND_TYPE_WND, self); + list_add_item(self->screen->child_list, (long)self->log_wnd); + self->log_wnd->parent = self->screen; + self->log_wnd->owner = self->screen; + self->log_wnd->bg_color = self->grey; + self->log_wnd->left = 10; + self->log_wnd->top = 10; + set_string(&(self->log_wnd->caption1), "Connection Log"); + /* ok button */ + but = xrdp_bitmap_create(60, 25, self->screen->bpp, WND_TYPE_BUTTON, self); + list_insert_item(self->log_wnd->child_list, 0, (long)but); + but->parent = self->log_wnd; + but->owner = self->log_wnd; + but->left = (400 - 60) - 10; + but->top = (400 - 25) - 10; + but->id = 1; + but->tab_stop = 1; + set_string(&but->caption1, "OK"); + self->log_wnd->focused_control = but; + /* set notify function */ + self->log_wnd->notify = xrdp_wm_log_wnd_notify; + } + xrdp_wm_set_focused(self, self->log_wnd); + xrdp_bitmap_invalidate(self->log_wnd, 0); + g_sleep(100); + return 0; +}