diff options
-rw-r--r-- | sesman/chansrv/chansrv.c | 78 | ||||
-rw-r--r-- | sesman/chansrv/chansrv.h | 9 | ||||
-rw-r--r-- | sesman/chansrv/clipboard.c | 181 | ||||
-rw-r--r-- | sesman/chansrv/sound.c | 114 | ||||
-rw-r--r-- | sesman/chansrv/sound.h | 31 |
5 files changed, 210 insertions, 203 deletions
diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c index 41176752..8e72f7a2 100644 --- a/sesman/chansrv/chansrv.c +++ b/sesman/chansrv/chansrv.c @@ -29,7 +29,6 @@ #include "list.h" #include "file.h" #include "file_loc.h" -#include "log.h" static struct trans* g_lis_trans = 0; static struct trans* g_con_trans = 0; @@ -108,7 +107,7 @@ send_init_response_message(void) { struct stream * s = (struct stream *)NULL; - log_message(LOG_LEVEL_INFO,"send_init_response_message:"); + LOGM((LOG_LEVEL_INFO,"send_init_response_message:")) s = trans_get_out_s(g_con_trans, 8192); if (s == 0) { @@ -129,7 +128,7 @@ send_channel_setup_response_message(void) { struct stream * s = (struct stream *)NULL; - log_message(LOG_LEVEL_DEBUG, "send_channel_setup_response_message:"); + LOGM((LOG_LEVEL_DEBUG, "send_channel_setup_response_message:")); s = trans_get_out_s(g_con_trans, 8192); if (s == 0) { @@ -150,7 +149,7 @@ send_channel_data_response_message(void) { struct stream * s = (struct stream *)NULL; - log_message(LOG_LEVEL_DEBUG, "send_channel_data_response_message:"); + LOGM((LOG_LEVEL_DEBUG, "send_channel_data_response_message:")); s = trans_get_out_s(g_con_trans, 8192); if (s == 0) { @@ -169,7 +168,7 @@ send_channel_data_response_message(void) static int APP_CC process_message_init(struct stream* s) { - log_message(LOG_LEVEL_DEBUG,"process_message_init:"); + LOGM((LOG_LEVEL_DEBUG, "process_message_init:")); return send_init_response_message(); } @@ -190,9 +189,10 @@ process_message_channel_setup(struct stream* s) g_cliprdr_chan_id = -1; g_rdpsnd_chan_id = -1; g_rdpdr_chan_id = -1; - log_message(LOG_LEVEL_DEBUG, "process_message_channel_setup:"); + LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup:")); in_uint16_le(s, num_chans); - log_message(LOG_LEVEL_DEBUG,"process_message_channel_setup: num_chans %d", num_chans); + LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup: num_chans %d", + num_chans)); for (index = 0; index < num_chans; index++) { ci = &(g_chan_items[g_num_chan_items]); @@ -200,8 +200,8 @@ process_message_channel_setup(struct stream* s) in_uint8a(s, ci->name, 8); in_uint16_le(s, ci->id); in_uint16_le(s, ci->flags); - log_message(LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' " - "id %d flags %8.8x", ci->name, ci->id, ci->flags); + LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' " + "id %d flags %8.8x", ci->name, ci->id, ci->flags)); if (g_strcasecmp(ci->name, "cliprdr") == 0) { g_cliprdr_index = g_num_chan_items; @@ -250,8 +250,8 @@ process_message_channel_data(struct stream* s) in_uint16_le(s, chan_flags); in_uint16_le(s, length); in_uint32_le(s, total_length); - log_message(LOG_LEVEL_DEBUG,"process_message_channel_data: chan_id %d " - "chan_flags %d", chan_id, chan_flags); + LOGM((LOG_LEVEL_DEBUG,"process_message_channel_data: chan_id %d " + "chan_flags %d", chan_id, chan_flags)); rv = send_channel_data_response_message(); if (rv == 0) { @@ -322,17 +322,15 @@ process_message(void) rv = process_message_channel_data_response(s); break; default: - log_message(LOG_LEVEL_ERROR, "process_message: error in process_message ", - "unknown msg %d", id); + LOGM((LOG_LEVEL_ERROR, "process_message: error in process_message ", + "unknown msg %d", id)); break; } if (rv != 0) { break; } - else { - s->p = next_msg; - } + s->p = next_msg; } return rv; } @@ -355,7 +353,7 @@ my_trans_data_in(struct trans* trans) { return 1; } - log_message(LOG_LEVEL_DEBUG,"my_trans_data_in:"); + LOGM((LOG_LEVEL_DEBUG, "my_trans_data_in:")); s = trans_get_in_s(trans); in_uint32_le(s, id); in_uint32_le(s, size); @@ -388,7 +386,7 @@ my_trans_conn_in(struct trans* trans, struct trans* new_trans) { return 1; } - log_message(LOG_LEVEL_DEBUG, "my_trans_conn_in:"); + LOGM((LOG_LEVEL_DEBUG, "my_trans_conn_in:")); g_con_trans = new_trans; g_con_trans->trans_data_in = my_trans_data_in; g_con_trans->header_size = 8; @@ -412,7 +410,8 @@ setup_listen(void) if (g_use_unix_socket) { g_lis_trans = trans_create(2, 8192, 8192); - g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + g_display_num); + g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", + 7200 + g_display_num); } else { @@ -423,7 +422,8 @@ setup_listen(void) error = trans_listen(g_lis_trans, port); if (error != 0) { - log_message(LOG_LEVEL_ERROR, "setup_listen: trans_listen failed for port %s", port); + LOGM((LOG_LEVEL_ERROR, "setup_listen: trans_listen failed for port %s", + port)); return 1; } return 0; @@ -439,7 +439,7 @@ channel_thread_loop(void* in_val) int error = 0; THREAD_RV rv = 0; - log_message(LOG_LEVEL_INFO, "channel_thread_loop: thread start"); + LOGM((LOG_LEVEL_INFO, "channel_thread_loop: thread start")); rv = 0; error = setup_listen(); if (error == 0) @@ -453,7 +453,7 @@ channel_thread_loop(void* in_val) { if (g_is_wait_obj_set(g_term_event)) { - log_message(LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set"); + LOGM((LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set")); clipboard_deinit(); sound_deinit(); dev_redir_deinit(); @@ -463,15 +463,16 @@ channel_thread_loop(void* in_val) { if (trans_check_wait_objs(g_lis_trans) != 0) { - log_message(LOG_LEVEL_INFO, "channel_thread_loop: trans_check_wait_objs error"); + LOGM((LOG_LEVEL_INFO, "channel_thread_loop: " + "trans_check_wait_objs error")); } } if (g_con_trans != 0) { if (trans_check_wait_objs(g_con_trans) != 0) { - log_message(LOG_LEVEL_INFO, "channel_thread_loop: " - "trans_check_wait_objs error resetting"); + LOGM((LOG_LEVEL_INFO, "channel_thread_loop: " + "trans_check_wait_objs error resetting")); clipboard_deinit(); sound_deinit(); dev_redir_deinit(); @@ -504,7 +505,7 @@ channel_thread_loop(void* in_val) g_lis_trans = 0; trans_delete(g_con_trans); g_con_trans = 0; - log_message(LOG_LEVEL_INFO, "channel_thread_loop: thread stop"); + LOGM((LOG_LEVEL_INFO, "channel_thread_loop: thread stop")); g_set_wait_obj(g_thread_done_event); return rv; } @@ -513,7 +514,7 @@ channel_thread_loop(void* in_val) void DEFAULT_CC term_signal_handler(int sig) { - log_message(LOG_LEVEL_INFO,"term_signal_handler: got signal %d", sig); + LOGM((LOG_LEVEL_INFO, "term_signal_handler: got signal %d", sig)); g_set_wait_obj(g_term_event); } @@ -521,7 +522,7 @@ term_signal_handler(int sig) void DEFAULT_CC nil_signal_handler(int sig) { - log_message(LOG_LEVEL_INFO, "nil_signal_handler: got signal %d", sig); + LOGM((LOG_LEVEL_INFO, "nil_signal_handler: got signal %d", sig)); g_set_wait_obj(g_term_event); } @@ -637,13 +638,16 @@ main(int argc, char** argv) int pid = 0; char text[256] = ""; char* display_text = (char *)NULL; - enum logReturns error; +#if XRDP_CHANNEL_LOG char cfg_file[256]; + enum logReturns error; +#endif g_init("xrdp-chansrv"); /* os_calls */ read_ini(); pid = g_getpid(); +#if XRDP_CHANNEL_LOG /* starting logging subsystem */ g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH); error = log_start(cfg_file,"XRDP-Chansrv"); @@ -665,22 +669,22 @@ main(int argc, char** argv) g_deinit(); g_exit(1); } - log_message(LOG_LEVEL_ALWAYS,"main: app started pid %d(0x%8.8x)", pid, pid); - + LOGM((LOG_LEVEL_ALWAYS, "main: app started pid %d(0x%8.8x)", pid, pid)); +#endif /* set up signal handler */ g_signal_kill(term_signal_handler); /* SIGKILL */ g_signal_terminate(term_signal_handler); /* SIGTERM */ g_signal_user_interrupt(term_signal_handler); /* SIGINT */ g_signal_pipe(nil_signal_handler); /* SIGPIPE */ display_text = g_getenv("DISPLAY"); - log_message(LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text); + LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text)); get_display_num_from_display(display_text); if (g_display_num == 0) { - log_message(LOG_LEVEL_ERROR, "main: error, display is zero"); + LOGM((LOG_LEVEL_ERROR, "main: error, display is zero")); return 1; } - log_message(LOG_LEVEL_INFO,"main: using DISPLAY %d", g_display_num); + LOGM((LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num)); g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid); g_term_event = g_create_wait_obj(text); g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid); @@ -690,7 +694,7 @@ main(int argc, char** argv) { if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0) { - log_message(LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"); + LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed")); break; } } @@ -699,13 +703,13 @@ main(int argc, char** argv) /* wait for thread to exit */ if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0) { - log_message(LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"); + LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed")); break; } } /* cleanup */ main_cleanup(); - log_message(LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid); + LOGM((LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid)); g_deinit(); return 0; } diff --git a/sesman/chansrv/chansrv.h b/sesman/chansrv/chansrv.h index b265458f..045c342f 100644 --- a/sesman/chansrv/chansrv.h +++ b/sesman/chansrv/chansrv.h @@ -5,6 +5,8 @@ #include "arch.h" #include "parse.h" +#define XRDP_CHANNEL_LOG 0 + struct chan_item { int id; @@ -28,4 +30,11 @@ main_cleanup(void); } \ } +#if XRDP_CHANNEL_LOG +#include "log.h" +#define LOGM(_args) do { log_message _args ; } while (0) +#else +#define LOGM(_args) +#endif + #endif diff --git a/sesman/chansrv/clipboard.c b/sesman/chansrv/clipboard.c index a3e83e5f..38afcd91 100644 --- a/sesman/chansrv/clipboard.c +++ b/sesman/chansrv/clipboard.c @@ -29,7 +29,6 @@ #include "parse.h" #include "os_calls.h" #include "chansrv.h" -#include "log.h" #include "clipboard.h" static Atom g_clipboard_atom = 0; @@ -80,7 +79,7 @@ clipboard_error_handler(Display* dis, XErrorEvent* xer) char text[256]; XGetErrorText(dis, xer->error_code, text, 255); - log_message(LOG_LEVEL_ERROR,"error [%s]", text); + LOGM((LOG_LEVEL_ERROR,"error [%s]", text)); return 0; } @@ -91,7 +90,7 @@ clipboard_error_handler(Display* dis, XErrorEvent* xer) int DEFAULT_CC clipboard_fatal_handler(Display* dis) { - log_message(LOG_LEVEL_ALWAYS,"fatal error, exiting"); + LOGM((LOG_LEVEL_ALWAYS, "fatal error, exiting")); main_cleanup(); return 0; } @@ -141,7 +140,7 @@ clipboard_init(void) int ver_min; Status st; - log_message(LOG_LEVEL_DEBUG,"xrdp-chansrv: in clipboard_init"); + LOGM((LOG_LEVEL_DEBUG, "xrdp-chansrv: in clipboard_init")); if (g_clip_up) { return 0; @@ -155,7 +154,7 @@ clipboard_init(void) g_display = XOpenDisplay(0); if (g_display == 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_init: XOpenDisplay failed"); + LOGM((LOG_LEVEL_ERROR, "clipboard_init: XOpenDisplay failed")); rv = 1; } if (rv == 0) @@ -163,7 +162,7 @@ clipboard_init(void) g_x_socket = XConnectionNumber(g_display); if (g_x_socket == 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_init: XConnectionNumber failed"); + LOGM((LOG_LEVEL_ERROR, "clipboard_init: XConnectionNumber failed")); rv = 2; } g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0); @@ -173,7 +172,7 @@ clipboard_init(void) g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False); if (g_clipboard_atom == None) { - log_message(LOG_LEVEL_ERROR,"clipboard_init: XInternAtom failed"); + LOGM((LOG_LEVEL_ERROR, "clipboard_init: XInternAtom failed")); rv = 3; } } @@ -181,15 +180,17 @@ clipboard_init(void) { if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy)) { - log_message(LOG_LEVEL_ERROR,"clipboard_init: no xfixes"); + LOGM((LOG_LEVEL_ERROR, "clipboard_init: no xfixes")); rv = 5; } } if (rv == 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_init: g_xfixes_event_base %d", g_xfixes_event_base); + LOGM((LOG_LEVEL_ERROR, "clipboard_init: g_xfixes_event_base %d", + g_xfixes_event_base)); st = XFixesQueryVersion(g_display, &ver_maj, &ver_min); - log_message(LOG_LEVEL_ERROR,"clipboard_init st %d, maj %d min %d", st, ver_maj, ver_min); + LOGM((LOG_LEVEL_ERROR, "clipboard_init st %d, maj %d min %d", st, + ver_maj, ver_min)); g_screen_num = DefaultScreen(g_display); g_screen = ScreenOfDisplay(g_display, g_screen_num); g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM", @@ -223,13 +224,13 @@ clipboard_init(void) out_uint32_le(s, 0); /* extra 4 bytes ? */ s_mark_end(s); size = (int)(s->end - s->data); - log_message(LOG_LEVEL_DEBUG,"clipboard_init: data out, sending " - "CLIPRDR_CONNECT (clip_msg_id = 1)"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_init: data out, sending " + "CLIPRDR_CONNECT (clip_msg_id = 1)")); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); if (rv != 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_init: send_channel_data failed " - "rv = %d", rv); + LOGM((LOG_LEVEL_ERROR, "clipboard_init: send_channel_data failed " + "rv = %d", rv)); rv = 4; } free_stream(s); @@ -242,7 +243,7 @@ clipboard_init(void) } else { - log_message(LOG_LEVEL_ERROR,"xrdp-chansrv: clipboard_init: error on exit"); + LOGM((LOG_LEVEL_ERROR, "xrdp-chansrv: clipboard_init: error on exit")); } return rv; } @@ -284,10 +285,11 @@ clipboard_send_data_request(void) int size; int rv; - log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_request:"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_send_data_request:")); if (!g_got_format_announce) { - log_message(LOG_LEVEL_ERROR,"clipboard_send_data_request: error, no format announce"); + LOGM((LOG_LEVEL_ERROR, "clipboard_send_data_request: error, " + "no format announce")); return 0; } g_got_format_announce = 0; @@ -299,8 +301,8 @@ clipboard_send_data_request(void) out_uint32_le(s, 0x0d); s_mark_end(s); size = (int)(s->end - s->data); - log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_request: data out, sending " - "CLIPRDR_DATA_REQUEST (clip_msg_id = 4)"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_send_data_request: data out, sending " + "CLIPRDR_DATA_REQUEST (clip_msg_id = 4)")); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); return rv; @@ -322,8 +324,8 @@ clipboard_send_format_ack(void) out_uint32_le(s, 0); /* extra 4 bytes ? */ s_mark_end(s); size = (int)(s->end - s->data); - log_message(LOG_LEVEL_DEBUG,"clipboard_send_format_ack: data out, sending " - "CLIPRDR_FORMAT_ACK (clip_msg_id = 3)"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_send_format_ack: data out, sending " + "CLIPRDR_FORMAT_ACK (clip_msg_id = 3)")); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); return rv; @@ -346,8 +348,8 @@ clipboard_send_format_announce(void) out_uint8s(s, 0x90); s_mark_end(s); size = (int)(s->end - s->data); - log_message(LOG_LEVEL_DEBUG,"clipboard_send_format_announce: data out, sending " - "CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_send_format_announce: data out, sending " + "CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)")); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); return rv; @@ -401,7 +403,7 @@ clipboard_send_data_response(void) num_chars = g_mbstowcs(0, g_last_clip_data, 0); if (num_chars < 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_send_data_response: bad string"); + LOGM((LOG_LEVEL_ERROR, "clipboard_send_data_response: bad string")); num_chars = 0; } } @@ -415,16 +417,16 @@ clipboard_send_data_response(void) out_uint32_le(s, num_chars * 2 + 2); /* length */ if (clipboard_out_unicode(s, g_last_clip_data, num_chars) != num_chars * 2) { - log_message(LOG_LEVEL_ERROR,"clipboard_send_data_response: error " - "clipboard_out_unicode didn't write right number of bytes"); + LOGM((LOG_LEVEL_ERROR,"clipboard_send_data_response: error " + "clipboard_out_unicode didn't write right number of bytes")); } out_uint16_le(s, 0); /* nil for string */ out_uint32_le(s, 0); s_mark_end(s); size = (int)(s->end - s->data); - log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_response: data out, sending " - "CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d num_chars %d", - size, num_chars); + LOGM((LOG_LEVEL_DEBUG,"clipboard_send_data_response: data out, sending " + "CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d num_chars %d", + size, num_chars)); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); return rv; @@ -494,14 +496,16 @@ static int APP_CC clipboard_process_format_announce(struct stream* s, int clip_msg_status, int clip_msg_len) { - log_message(LOG_LEVEL_DEBUG,"clipboard_process_format_announce: CLIPRDR_FORMAT_ANNOUNCE"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_process_format_announce: " + "CLIPRDR_FORMAT_ANNOUNCE")); //g_hexdump(s->p, s->end - s->p); clipboard_send_format_ack(); g_got_format_announce = 1; g_data_in_up_to_date = 0; if (clipboard_set_selection_owner() != 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_process_format_announce: XSetSelectionOwner failed"); + LOGM((LOG_LEVEL_ERROR, "clipboard_process_format_announce: " + "XSetSelectionOwner failed")); } return 0; } @@ -511,7 +515,7 @@ static int APP_CC clipboard_prcoess_format_ack(struct stream* s, int clip_msg_status, int clip_msg_len) { - log_message(LOG_LEVEL_DEBUG,"clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK")); //g_hexdump(s->p, s->end - s->p); return 0; } @@ -521,7 +525,8 @@ static int APP_CC clipboard_process_data_request(struct stream* s, int clip_msg_status, int clip_msg_len) { - log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_request: CLIPRDR_DATA_REQUEST"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_request: " + "CLIPRDR_DATA_REQUEST")); //g_hexdump(s->p, s->end - s->p); clipboard_send_data_response(); return 0; @@ -539,7 +544,8 @@ clipboard_process_data_response(struct stream* s, int clip_msg_status, int index; int data_in_len; - log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_response: CLIPRDR_DATA_RESPONSE"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_response: " + "CLIPRDR_DATA_RESPONSE")); g_waiting_for_data_response = 0; len = (int)(s->end - s->p); if (len < 1) @@ -590,8 +596,8 @@ clipboard_process_data_response(struct stream* s, int clip_msg_status, lxev = &(g_selection_request_event[index]); clipboard_provide_selection(lxev, lxev->target, 8, g_data_in, data_in_len); - log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_response: requestor %d data_in_len %d", - lxev->requestor, data_in_len); + LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_response: requestor %d " + "data_in_len %d", lxev->requestor, data_in_len)); } } g_selection_request_event_count = 0; @@ -657,7 +663,8 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length, clip_msg_len); break; default: - log_message(LOG_LEVEL_ERROR,"clipboard_data_in: unknown clip_msg_id %d", clip_msg_id); + LOGM((LOG_LEVEL_ERROR, "clipboard_data_in: unknown clip_msg_id %d", + clip_msg_id)); break; } XFlush(g_display); @@ -685,13 +692,13 @@ clipboard_event_selection_owner_notify(XEvent* xevent) XFixesSelectionNotifyEvent* lxevent; lxevent = (XFixesSelectionNotifyEvent*)xevent; - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: " - "window %d subtype %d owner %d g_wnd %d", - lxevent->window, lxevent->subtype, lxevent->owner, g_wnd); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: " + "window %d subtype %d owner %d g_wnd %d", + lxevent->window, lxevent->subtype, lxevent->owner, g_wnd)); if (lxevent->owner == g_wnd) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: skipping, " - "onwer == g_wnd"); + LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: skipping, " + "onwer == g_wnd")); g_got_selection = 1; return 0; } @@ -811,7 +818,10 @@ clipboard_event_selection_notify(XEvent* xevent) int* atoms; Atom type; - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify:"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_notify:")); + data_size = 0; + n_items = 0; + fmt = 0; convert_to_string = 0; convert_to_utf8 = 0; send_format_announce = 0; @@ -821,8 +831,8 @@ clipboard_event_selection_notify(XEvent* xevent) lxevent = (XSelectionEvent*)xevent; if (lxevent->property == None) { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: clip could " - "not be converted"); + LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: clip could " + "not be converted")); rv = 1; } if (rv == 0) @@ -832,8 +842,8 @@ clipboard_event_selection_notify(XEvent* xevent) &n_items, &data, &data_size); if (rv != 0) { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: " - "clipboard_get_window_property failed error %d", rv); + LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: " + "clipboard_get_window_property failed error %d", rv)); } XDeleteProperty(g_display, lxevent->requestor, lxevent->property); } @@ -849,8 +859,8 @@ clipboard_event_selection_notify(XEvent* xevent) for (index = 0; index < n_items; index++) { atom = atoms[index]; - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: %d %s %d", atom, - XGetAtomName(g_display, atom), XA_STRING); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: %d %s %d", + atom, XGetAtomName(g_display, atom), XA_STRING)); if (atom == g_utf8_atom) { convert_to_utf8 = 1; @@ -863,15 +873,15 @@ clipboard_event_selection_notify(XEvent* xevent) } else { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: error, target is " - "'TARGETS' and type[%d] or fmt[%d] not right, should be " - "type[%d], fmt[%d]", type, fmt, XA_ATOM, 32); + LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: error, " + "target is 'TARGETS' and type[%d] or fmt[%d] not right, " + "should be type[%d], fmt[%d]", type, fmt, XA_ATOM, 32)); } } else if (lxevent->target == g_utf8_atom) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: UTF8_STRING data_size %d", - data_size); + LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: UTF8_STRING " + "data_size %d", data_size)); g_free(g_last_clip_data); g_last_clip_size = data_size; g_last_clip_data = g_malloc(g_last_clip_size + 1, 0); @@ -882,8 +892,8 @@ clipboard_event_selection_notify(XEvent* xevent) } else if (lxevent->target == XA_STRING) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: XA_STRING data_size %d", - data_size); + LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: XA_STRING " + "data_size %d", data_size)); g_free(g_last_clip_data); g_last_clip_size = data_size; g_last_clip_data = g_malloc(g_last_clip_size + 1, 0); @@ -894,12 +904,14 @@ clipboard_event_selection_notify(XEvent* xevent) } else { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: unknown target"); + LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: " + "unknown target")); } } else { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: unknown selection"); + LOGM((LOG_LEVEL_ERROR,"clipboard_event_selection_notify: " + "unknown selection")); } } if (convert_to_utf8) @@ -941,7 +953,7 @@ clipboard_event_selection_notify(XEvent* xevent) static int APP_CC clipboard_event_selection_request(XEvent* xevent) { - XEvent xev; + //XEvent xev; XSelectionRequestEvent* lxev; tui32 ui32[8]; Atom type; @@ -951,19 +963,21 @@ clipboard_event_selection_request(XEvent* xevent) char* xdata; lxev = (XSelectionRequestEvent*)xevent; - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_wnd %d, " - ".requestor %d .owner %d .selection %d '%s' .target %d .property %d", - g_wnd, lxev->requestor, lxev->owner, lxev->selection, - XGetAtomName(g_display, lxev->selection), - lxev->target, lxev->property); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_wnd %d, " + ".requestor %d .owner %d .selection %d '%s' .target %d .property %d", + g_wnd, lxev->requestor, lxev->owner, lxev->selection, + XGetAtomName(g_display, lxev->selection), + lxev->target, lxev->property)); if (lxev->property == None) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: lxev->property is None"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: " + "lxev->property is None")); } else if (lxev->target == g_targets_atom) { /* requestor is asking what the selection can be converted to */ - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_targets_atom"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: " + "g_targets_atom")); ui32[0] = g_targets_atom; ui32[1] = g_timestamp_atom; ui32[2] = g_multiple_atom; @@ -974,29 +988,33 @@ clipboard_event_selection_request(XEvent* xevent) else if (lxev->target == g_timestamp_atom) { /* requestor is asking the time I got the selection */ - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_timestamp_atom"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: " + "g_timestamp_atom")); ui32[0] = g_selection_time; return clipboard_provide_selection(lxev, XA_INTEGER, 32, (char*)ui32, 1); } else if (lxev->target == g_multiple_atom) { /* target, property pairs */ - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_multiple_atom"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: " + "g_multiple_atom")); +#if 0 if (clipboard_get_window_property(xev.xselection.requestor, xev.xselection.property, &type, &fmt, &n_items, &xdata, &xdata_size) == 0) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_multiple_atom " - "n_items %d", n_items); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_multiple_atom " + "n_items %d", n_items)); /* todo */ g_free(xdata); } +#endif } else if ((lxev->target == XA_STRING) || (lxev->target == g_utf8_atom)) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: %s", - XGetAtomName(g_display, lxev->target)); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: %s", + XGetAtomName(g_display, lxev->target))); if (g_data_in_up_to_date) { return clipboard_provide_selection(lxev, lxev->target, 8, @@ -1004,7 +1022,8 @@ clipboard_event_selection_request(XEvent* xevent) } if (g_selection_request_event_count > 10) { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_request: error, too many requests"); + LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_request: error, " + "too many requests")); } else { @@ -1022,8 +1041,8 @@ clipboard_event_selection_request(XEvent* xevent) } else { - log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_request: unknown " - "target %s", XGetAtomName(g_display, lxev->target)); + LOGM((LOG_LEVEL_ERROR,"clipboard_event_selection_request: unknown " + "target %s", XGetAtomName(g_display, lxev->target))); } clipboard_refuse_selection(lxev); return 0; @@ -1044,7 +1063,7 @@ clipboard_event_selection_request(XEvent* xevent) static int APP_CC clipboard_event_selection_clear(XEvent* xevent) { - log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_clear:"); + LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_clear:")); return 0; } @@ -1105,7 +1124,7 @@ clipboard_check_wait_objs(void) if (XPending(g_display) < 1) { /* something is wrong, should not get here */ - log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs: sck closed"); + LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs: sck closed")); return 0; } if (g_waiting_for_data_response) @@ -1114,8 +1133,8 @@ clipboard_check_wait_objs(void) g_waiting_for_data_response_time; if (time_diff > 1000) { - log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs: warning, waiting for " - "data response too long"); + LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs: warning, " + "waiting for data response too long")); } } while (XPending(g_display) > 0) @@ -1144,8 +1163,8 @@ clipboard_check_wait_objs(void) clipboard_event_selection_owner_notify(&xevent); break; } - log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs unknown type %d", - xevent.type); + LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs unknown type %d", + xevent.type)); break; } } diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c index 6a86d97d..e4d54bb0 100644 --- a/sesman/chansrv/sound.c +++ b/sesman/chansrv/sound.c @@ -17,6 +17,7 @@ */ #include "sound.h" +#include "thread_calls.h" extern int g_rdpsnd_chan_id; /* in chansrv.c */ extern int g_display_num; /* in chansrv.c */ @@ -26,6 +27,11 @@ static struct trans *g_audio_c_trans = 0; // connection static int g_training_sent_time = 0; static int g_cBlockNo = 0; +#if defined(XRDP_SIMPLESOUND) +static void* DEFAULT_CC +read_raw_audio_data(void* arg); +#endif + /*****************************************************************************/ static int APP_CC sound_send_server_formats(void) @@ -164,7 +170,7 @@ sound_send_wave_data(char* data, int data_bytes) /* part one of 2 PDU wave info */ - LOG(3, ("sound_send_wave_data: sending %d bytes", data_bytes)); + LOG(10, ("sound_send_wave_data: sending %d bytes", data_bytes)); make_stream(s); init_stream(s, data_bytes); @@ -177,7 +183,7 @@ sound_send_wave_data(char* data, int data_bytes) g_cBlockNo++; out_uint8(s, g_cBlockNo); - LOG(3, ("sound_send_wave_data: sending time %d, g_cBlockNo %d", + LOG(10, ("sound_send_wave_data: sending time %d, g_cBlockNo %d", time & 0xffff, g_cBlockNo & 0xff)); out_uint8s(s, 3); @@ -227,7 +233,7 @@ sound_process_wave_confirm(struct stream* s, int size) in_uint16_le(s, wTimeStamp); in_uint8(s, cConfirmedBlockNo); - LOG(3, ("sound_process_wave_confirm: wTimeStamp %d, cConfirmedBlockNo %d", + LOG(10, ("sound_process_wave_confirm: wTimeStamp %d, cConfirmedBlockNo %d", wTimeStamp, cConfirmedBlockNo)); return 0; @@ -330,9 +336,8 @@ sound_init(void) #if defined(XRDP_SIMPLESOUND) - // start thread to read raw audio data from pulseaudio device - pthread_create(&thread, 0, read_raw_audio_data, NULL); - pthread_detach(thread); + /* start thread to read raw audio data from pulseaudio device */ + tc_thread_create(read_raw_audio_data, 0); #endif @@ -434,113 +439,114 @@ sound_check_wait_objs(void) #if defined(XRDP_SIMPLESOUND) +static int DEFAULT_CC +sttrans_data_in(struct trans* self) +{ + LOG(0, ("sttrans_data_in:\n")); + return 0; +} + /** * read raw audio data from pulseaudio device and write it * to a unix domain socket on which trans server is listening */ -static void * +static void* DEFAULT_CC read_raw_audio_data(void* arg) { - struct sockaddr_un serv_addr; pa_sample_spec samp_spec; pa_simple* simple = NULL; - uint32_t bytes_read; - uint8_t audio_buf[AUDIO_BUF_SIZE + 8]; char* cptr; int i; int error; - int skt_fd; + struct trans* strans; + char path[256]; + struct stream* outs; - // create client socket - if ((skt_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + strans = trans_create(TRANS_MODE_UNIX, 8192, 8192); + if (strans == 0) { - LOG(0, ("read_raw_audio_data: error creating unix domain socket\n")); - return NULL; + LOG(0, ("read_raw_audio_data: trans_create failed\n")); + return 0; } - - // setup server address and bind to it - memset(&serv_addr, 0, sizeof(struct sockaddr_un)); - serv_addr.sun_family = AF_UNIX; - g_snprintf(serv_addr.sun_path, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num); - - if (connect(skt_fd, (struct sockaddr *) &serv_addr, sizeof(struct sockaddr_un)) < 0) + strans->trans_data_in = sttrans_data_in; + g_snprintf(path, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num); + if (trans_connect(strans, "", path, 100) != 0) { - LOG(0, ("read_raw_audio_data: error connecting to server\n")); - close(skt_fd); - return NULL; + LOG(0, ("read_raw_audio_data: trans_connect failed\n")); + trans_delete(strans); + return 0; } - // setup audio format + /* setup audio format */ samp_spec.format = PA_SAMPLE_S16LE; samp_spec.rate = 44100; samp_spec.channels = 2; - // if we are root, then for first 8 seconds connection to pulseaudo server - // fails; if we are non-root, then connection succeeds on first attempt; - // for now we have changed code to be non-root, but this may change in the - // future - so pretend we are root and try connecting to pulseaudio server - // for upto one minute + /* if we are root, then for first 8 seconds connection to pulseaudo server + fails; if we are non-root, then connection succeeds on first attempt; + for now we have changed code to be non-root, but this may change in the + future - so pretend we are root and try connecting to pulseaudio server + for upto one minute */ for (i = 0; i < 60; i++) { simple = pa_simple_new(NULL, "xrdp", PA_STREAM_RECORD, NULL, "record", &samp_spec, NULL, NULL, &error); if (simple) { - // connected to pulseaudio server + /* connected to pulseaudio server */ LOG(0, ("read_raw_audio_data: connected to pulseaudio server\n")); break; } LOG(0, ("read_raw_audio_data: ERROR creating PulseAudio async interface\n")); LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error))); - sleep(1); + g_sleep(1000); } if (i == 60) { - // failed to connect to audio server - close(skt_fd); + /* failed to connect to audio server */ + trans_delete(strans); return NULL; } - // insert header just once - cptr = audio_buf; - ins_uint32_le(cptr, 0); - ins_uint32_le(cptr, AUDIO_BUF_SIZE + 8); + /* insert header just once */ + outs = trans_get_out_s(strans, 8192); + out_uint32_le(outs, 0); + out_uint32_le(outs, AUDIO_BUF_SIZE + 8); + cptr = outs->p; + out_uint8s(outs, AUDIO_BUF_SIZE); + s_mark_end(outs); while (1) { - // read a block of raw audio data... - if ((bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error)) < 0) + /* read a block of raw audio data... */ + g_memset(cptr, 0, 4); + bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error); + if (bytes_read < 0) { LOG(0, ("read_raw_audio_data: ERROR reading from pulseaudio stream\n")); LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error))); break; } - - // bug workaround: - // even when there is no audio data, pulseaudio is returning without - // errors but the data itself is zero; we use this zero data to - // determine that there is no audio data present + /* bug workaround: + even when there is no audio data, pulseaudio is returning without + errors but the data itself is zero; we use this zero data to + determine that there is no audio data present */ if (*cptr == 0 && *(cptr + 1) == 0 && *(cptr + 2) == 0 && *(cptr + 3) == 0) { - usleep(10000); + g_sleep(10); continue; } - - // ... and write it to a unix domain socket - if (write(skt_fd, audio_buf, AUDIO_BUF_SIZE + 8) < 0) + if (trans_force_write_s(strans, outs) != 0) { LOG(0, ("read_raw_audio_data: ERROR writing audio data to server\n")); break; } } - -done: - pa_simple_free(simple); - close(skt_fd); + trans_delete(strans); return NULL; } diff --git a/sesman/chansrv/sound.h b/sesman/chansrv/sound.h index a2d1704a..8171680d 100644 --- a/sesman/chansrv/sound.h +++ b/sesman/chansrv/sound.h @@ -19,9 +19,6 @@ #ifndef _SOUND_H_ #define _SOUND_H_ -#include <sys/socket.h> -#include <sys/un.h> - #if defined(XRDP_SIMPLESOUND) #include <pulse/simple.h> #include <pulse/error.h> @@ -43,29 +40,6 @@ #define print_got_here() #endif -/** - * insert a uint32_t value into specified byte array - * - * @param p pointer to byte array - * @param v value to insert into byte array - */ - -#if defined(B_ENDIAN) || defined(NEED_ALIGN) -#define ins_uint32_le(p, v) \ -{ \ - *p++ = (unsigned char) v; \ - *p++ = (unsigned char) (v >> 8); \ - *p++ = (unsigned char) (v >> 16); \ - *p++ = (unsigned char) (v >> 24); \ -} -#else -#define ins_uint32_le(p, v) \ -{ \ - *((uint32_t *) p) = v; \ - p += 4; \ -} -#endif - #define AUDIO_BUF_SIZE 2048 #define SNDC_CLOSE 0x01 @@ -93,9 +67,4 @@ int APP_CC sound_data_in(struct stream* s, int chan_id, int chan_flags, int length, int total_length); -#if defined(XRDP_SIMPLESOUND) -static void* -read_raw_audio_data(void* arg); -#endif - #endif |