summaryrefslogtreecommitdiffstats
path: root/xrdp
diff options
context:
space:
mode:
Diffstat (limited to 'xrdp')
-rw-r--r--xrdp/funcs.c381
-rw-r--r--xrdp/lang.c412
-rw-r--r--xrdp/xrdp.c859
-rw-r--r--xrdp/xrdp.h40
-rw-r--r--xrdp/xrdp_bitmap.c3180
-rw-r--r--xrdp/xrdp_cache.c1090
-rw-r--r--xrdp/xrdp_font.c359
-rw-r--r--xrdp/xrdp_listen.c751
-rw-r--r--xrdp/xrdp_login_wnd.c995
-rw-r--r--xrdp/xrdp_mm.c3548
-rw-r--r--xrdp/xrdp_painter.c1446
-rw-r--r--xrdp/xrdp_process.c318
-rw-r--r--xrdp/xrdp_region.c535
-rw-r--r--xrdp/xrdp_types.h39
-rw-r--r--xrdp/xrdp_wm.c2921
-rw-r--r--xrdp/xrdpwin.c975
16 files changed, 9422 insertions, 8427 deletions
diff --git a/xrdp/funcs.c b/xrdp/funcs.c
index d30d5b90..82662fa9 100644
--- a/xrdp/funcs.c
+++ b/xrdp/funcs.c
@@ -1,240 +1,269 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- simple functions
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * simple functions
+ */
#include "xrdp.h"
/*****************************************************************************/
/* returns boolean */
int APP_CC
-rect_contains_pt(struct xrdp_rect* in, int x, int y)
+rect_contains_pt(struct xrdp_rect *in, int x, int y)
{
- if (x < in->left)
- {
- return 0;
- }
- if (y < in->top)
- {
- return 0;
- }
- if (x >= in->right)
- {
- return 0;
- }
- if (y >= in->bottom)
- {
- return 0;
- }
- return 1;
+ if (x < in->left)
+ {
+ return 0;
+ }
+
+ if (y < in->top)
+ {
+ return 0;
+ }
+
+ if (x >= in->right)
+ {
+ return 0;
+ }
+
+ if (y >= in->bottom)
+ {
+ return 0;
+ }
+
+ return 1;
}
/*****************************************************************************/
int APP_CC
-rect_intersect(struct xrdp_rect* in1, struct xrdp_rect* in2,
- struct xrdp_rect* out)
+rect_intersect(struct xrdp_rect *in1, struct xrdp_rect *in2,
+ struct xrdp_rect *out)
{
- int rv;
- struct xrdp_rect dumby;
-
- if (out == 0)
- {
- out = &dumby;
- }
- *out = *in1;
- if (in2->left > in1->left)
- {
- out->left = in2->left;
- }
- if (in2->top > in1->top)
- {
- out->top = in2->top;
- }
- if (in2->right < in1->right)
- {
- out->right = in2->right;
- }
- if (in2->bottom < in1->bottom)
- {
- out->bottom = in2->bottom;
- }
- rv = !ISRECTEMPTY(*out);
- if (!rv)
- {
- g_memset(out, 0, sizeof(struct xrdp_rect));
- }
- return rv;
+ int rv;
+ struct xrdp_rect dumby;
+
+ if (out == 0)
+ {
+ out = &dumby;
+ }
+
+ *out = *in1;
+
+ if (in2->left > in1->left)
+ {
+ out->left = in2->left;
+ }
+
+ if (in2->top > in1->top)
+ {
+ out->top = in2->top;
+ }
+
+ if (in2->right < in1->right)
+ {
+ out->right = in2->right;
+ }
+
+ if (in2->bottom < in1->bottom)
+ {
+ out->bottom = in2->bottom;
+ }
+
+ rv = !ISRECTEMPTY(*out);
+
+ if (!rv)
+ {
+ g_memset(out, 0, sizeof(struct xrdp_rect));
+ }
+
+ return rv;
}
/*****************************************************************************/
/* returns boolean */
int APP_CC
-rect_contained_by(struct xrdp_rect* in1, int left, int top,
+rect_contained_by(struct xrdp_rect *in1, int left, int top,
int right, int bottom)
{
- if (left < in1->left || top < in1->top ||
- right > in1->right || bottom > in1->bottom)
- {
- return 0;
- }
- else
- {
- return 1;
- }
+ if (left < in1->left || top < in1->top ||
+ right > in1->right || bottom > in1->bottom)
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
}
/*****************************************************************************/
/* adjust the bounds to fit in the bitmap */
/* return false if there is nothing to draw else return true */
int APP_CC
-check_bounds(struct xrdp_bitmap* b, int* x, int* y, int* cx, int* cy)
+check_bounds(struct xrdp_bitmap *b, int *x, int *y, int *cx, int *cy)
{
- if (*x >= b->width)
- {
- return 0;
- }
- if (*y >= b->height)
- {
- return 0;
- }
- if (*x < 0)
- {
- *cx += *x;
- *x = 0;
- }
- if (*y < 0)
- {
- *cy += *y;
- *y = 0;
- }
- if (*cx <= 0)
- {
- return 0;
- }
- if (*cy <= 0)
- {
- return 0;
- }
- if (*x + *cx > b->width)
- {
- *cx = b->width - *x;
- }
- if (*y + *cy > b->height)
- {
- *cy = b->height - *y;
- }
- return 1;
+ if (*x >= b->width)
+ {
+ return 0;
+ }
+
+ if (*y >= b->height)
+ {
+ return 0;
+ }
+
+ if (*x < 0)
+ {
+ *cx += *x;
+ *x = 0;
+ }
+
+ if (*y < 0)
+ {
+ *cy += *y;
+ *y = 0;
+ }
+
+ if (*cx <= 0)
+ {
+ return 0;
+ }
+
+ if (*cy <= 0)
+ {
+ return 0;
+ }
+
+ if (*x + *cx > b->width)
+ {
+ *cx = b->width - *x;
+ }
+
+ if (*y + *cy > b->height)
+ {
+ *cy = b->height - *y;
+ }
+
+ return 1;
}
/*****************************************************************************/
/* add a ch at index position in text, index starts at 0 */
/* if index = -1 add it to the end */
int APP_CC
-add_char_at(char* text, int text_size, twchar ch, int index)
+add_char_at(char *text, int text_size, twchar ch, int index)
{
- int len;
- int i;
- twchar* wstr;
-
- len = g_mbstowcs(0, text, 0);
- wstr = (twchar*)g_malloc((len + 16) * sizeof(twchar), 0);
- g_mbstowcs(wstr, text, len + 1);
- if ((index >= len) || (index < 0))
- {
- wstr[len] = ch;
+ int len;
+ int i;
+ twchar *wstr;
+
+ len = g_mbstowcs(0, text, 0);
+ wstr = (twchar *)g_malloc((len + 16) * sizeof(twchar), 0);
+ g_mbstowcs(wstr, text, len + 1);
+
+ if ((index >= len) || (index < 0))
+ {
+ wstr[len] = ch;
+ wstr[len + 1] = 0;
+ g_wcstombs(text, wstr, text_size);
+ g_free(wstr);
+ return 0;
+ }
+
+ for (i = (len - 1); i >= index; i--)
+ {
+ wstr[i + 1] = wstr[i];
+ }
+
+ wstr[i + 1] = ch;
wstr[len + 1] = 0;
g_wcstombs(text, wstr, text_size);
g_free(wstr);
return 0;
- }
- for (i = (len - 1); i >= index; i--)
- {
- wstr[i + 1] = wstr[i];
- }
- wstr[i + 1] = ch;
- wstr[len + 1] = 0;
- g_wcstombs(text, wstr, text_size);
- g_free(wstr);
- return 0;
}
/*****************************************************************************/
/* remove a ch at index position in text, index starts at 0 */
/* if index = -1 remove it from the end */
int APP_CC
-remove_char_at(char* text, int text_size, int index)
+remove_char_at(char *text, int text_size, int index)
{
- int len;
- int i;
- twchar* wstr;
+ int len;
+ int i;
+ twchar *wstr;
+
+ len = g_mbstowcs(0, text, 0);
+
+ if (len <= 0)
+ {
+ return 0;
+ }
+
+ wstr = (twchar *)g_malloc((len + 16) * sizeof(twchar), 0);
+ g_mbstowcs(wstr, text, len + 1);
+
+ if ((index >= (len - 1)) || (index < 0))
+ {
+ wstr[len - 1] = 0;
+ g_wcstombs(text, wstr, text_size);
+ g_free(wstr);
+ return 0;
+ }
+
+ for (i = index; i < (len - 1); i++)
+ {
+ wstr[i] = wstr[i + 1];
+ }
- len = g_mbstowcs(0, text, 0);
- if (len <= 0)
- {
- return 0;
- }
- wstr = (twchar*)g_malloc((len + 16) * sizeof(twchar), 0);
- g_mbstowcs(wstr, text, len + 1);
- if ((index >= (len - 1)) || (index < 0))
- {
wstr[len - 1] = 0;
g_wcstombs(text, wstr, text_size);
g_free(wstr);
return 0;
- }
- for (i = index; i < (len - 1); i++)
- {
- wstr[i] = wstr[i + 1];
- }
- wstr[len - 1] = 0;
- g_wcstombs(text, wstr, text_size);
- g_free(wstr);
- return 0;
}
/*****************************************************************************/
int APP_CC
-set_string(char** in_str, const char* in)
+set_string(char **in_str, const char *in)
{
- if (in_str == 0)
- {
+ if (in_str == 0)
+ {
+ return 0;
+ }
+
+ g_free(*in_str);
+ *in_str = g_strdup(in);
return 0;
- }
- g_free(*in_str);
- *in_str = g_strdup(in);
- return 0;
}
/*****************************************************************************/
int APP_CC
-wchar_repeat(twchar* dest, int dest_size_in_wchars, twchar ch, int repeat)
+wchar_repeat(twchar *dest, int dest_size_in_wchars, twchar ch, int repeat)
{
- int index;
+ int index;
- for (index = 0; index < repeat; index++)
- {
- if (index >= dest_size_in_wchars)
+ for (index = 0; index < repeat; index++)
{
- break;
+ if (index >= dest_size_in_wchars)
+ {
+ break;
+ }
+
+ dest[index] = ch;
}
- dest[index] = ch;
- }
- return 0;
+
+ return 0;
}
diff --git a/xrdp/lang.c b/xrdp/lang.c
index 1c13839f..29031ea2 100644
--- a/xrdp/lang.c
+++ b/xrdp/lang.c
@@ -1,25 +1,23 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2006-2010
-
- keylayout
- maximum unicode 19996(0x4e00)
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * keylayout
+ * maximum unicode 19996(0x4e00)
+ */
#include "xrdp.h"
#include "log.h"
@@ -28,223 +26,241 @@
code1 is regular scancode, code2 is extended scancode */
struct codepair
{
- tui8 code1;
- tui8 code2;
+ tui8 code1;
+ tui8 code2;
};
static struct codepair g_map[] =
{
- { 0, 0 }, { 9, 0 }, { 10, 0 }, { 11, 0 }, { 12, 0 }, /* 0 - 4 */
- { 13, 0 }, { 14, 0 }, { 15, 0 }, { 16, 0 }, { 17, 0 }, /* 5 - 9 */
- { 18, 0 }, { 19, 0 }, { 20, 0 }, { 21, 0 }, { 22, 0 }, /* 10 - 14 */
- { 23, 0 }, { 24, 0 }, { 25, 0 }, { 26, 0 }, { 27, 0 }, /* 15 - 19 */
- { 28, 0 }, { 29, 0 }, { 30, 0 }, { 31, 0 }, { 32, 0 }, /* 20 - 24 */
- { 33, 0 }, { 34, 0 }, { 35, 0 }, { 36, 108 }, { 37, 109 }, /* 25 - 29 */
- { 38, 0 }, { 39, 0 }, { 40, 0 }, { 41, 0 }, { 42, 0 }, /* 30 - 34 */
- { 43, 0 }, { 44, 0 }, { 45, 0 }, { 46, 0 }, { 47, 0 }, /* 35 - 39 */
- { 48, 0 }, { 49, 0 }, { 50, 0 }, { 51, 0 }, { 52, 0 }, /* 40 - 44 */
- { 53, 0 }, { 54, 0 }, { 55, 0 }, { 56, 0 }, { 57, 0 }, /* 45 - 49 */
- { 58, 0 }, { 59, 0 }, { 60, 0 }, { 61, 112 }, { 62, 0 }, /* 50 - 54 */
- { 63, 111 }, { 64, 113 }, { 65, 0 }, { 66, 0 }, { 67, 0 }, /* 55 - 59 */
- { 68, 0 }, { 69, 0 }, { 70, 0 }, { 71, 0 }, { 72, 0 }, /* 60 - 64 */
- { 73, 0 }, { 74, 0 }, { 75, 0 }, { 76, 0 }, { 77, 0 }, /* 65 - 69 */
- { 78, 0 }, { 79, 97 }, { 80, 98 }, { 81, 99 }, { 82, 0 }, /* 70 - 74 */
- { 83, 100 }, { 84, 0 }, { 85, 102 }, { 86, 0 }, { 87, 103 }, /* 75 - 79 */
- { 88, 104 }, { 89, 105 }, { 90, 106 }, { 91, 107 }, { 92, 0 }, /* 80 - 84 */
- { 93, 0 }, { 94, 0 }, { 95, 0 }, { 96, 0 }, { 97, 0 }, /* 85 - 89 */
- { 98, 0 }, { 0, 115 }, { 0, 116 }, { 0, 117 }, { 102, 0 }, /* 90 - 94 */
- { 103, 0 }, { 104, 0 }, { 105, 0 }, { 106, 0 }, { 107, 0 }, /* 95 - 99 */
- { 108, 0 }, { 109, 0 }, { 110, 0 }, { 111, 0 }, { 112, 0 }, /* 100 - 104 */
- { 113, 0 }, { 114, 0 }, { 115, 0 }, { 116, 0 }, { 117, 0 }, /* 105 - 109 */
- { 118, 0 }, { 119, 0 }, { 120, 0 }, { 121, 0 }, { 122, 0 }, /* 110 - 114 */
- { 123, 0 }, { 124, 0 }, { 125, 0 }, { 126, 0 }, { 127, 0 }, /* 115 - 119 */
- { 128, 0 }, { 129, 0 }, { 130, 0 }, { 131, 0 }, { 132, 0 }, /* 120 - 124 */
- { 133, 0 }, { 134, 0 }, { 135, 0 } /* 125 - 127 */
+ { 0, 0 }, { 9, 0 }, { 10, 0 }, { 11, 0 }, { 12, 0 }, /* 0 - 4 */
+ { 13, 0 }, { 14, 0 }, { 15, 0 }, { 16, 0 }, { 17, 0 }, /* 5 - 9 */
+ { 18, 0 }, { 19, 0 }, { 20, 0 }, { 21, 0 }, { 22, 0 }, /* 10 - 14 */
+ { 23, 0 }, { 24, 0 }, { 25, 0 }, { 26, 0 }, { 27, 0 }, /* 15 - 19 */
+ { 28, 0 }, { 29, 0 }, { 30, 0 }, { 31, 0 }, { 32, 0 }, /* 20 - 24 */
+ { 33, 0 }, { 34, 0 }, { 35, 0 }, { 36, 108 }, { 37, 109 }, /* 25 - 29 */
+ { 38, 0 }, { 39, 0 }, { 40, 0 }, { 41, 0 }, { 42, 0 }, /* 30 - 34 */
+ { 43, 0 }, { 44, 0 }, { 45, 0 }, { 46, 0 }, { 47, 0 }, /* 35 - 39 */
+ { 48, 0 }, { 49, 0 }, { 50, 0 }, { 51, 0 }, { 52, 0 }, /* 40 - 44 */
+ { 53, 0 }, { 54, 0 }, { 55, 0 }, { 56, 0 }, { 57, 0 }, /* 45 - 49 */
+ { 58, 0 }, { 59, 0 }, { 60, 0 }, { 61, 112 }, { 62, 0 }, /* 50 - 54 */
+ { 63, 111 }, { 64, 113 }, { 65, 0 }, { 66, 0 }, { 67, 0 }, /* 55 - 59 */
+ { 68, 0 }, { 69, 0 }, { 70, 0 }, { 71, 0 }, { 72, 0 }, /* 60 - 64 */
+ { 73, 0 }, { 74, 0 }, { 75, 0 }, { 76, 0 }, { 77, 0 }, /* 65 - 69 */
+ { 78, 0 }, { 79, 97 }, { 80, 98 }, { 81, 99 }, { 82, 0 }, /* 70 - 74 */
+ { 83, 100 }, { 84, 0 }, { 85, 102 }, { 86, 0 }, { 87, 103 }, /* 75 - 79 */
+ { 88, 104 }, { 89, 105 }, { 90, 106 }, { 91, 107 }, { 92, 0 }, /* 80 - 84 */
+ { 93, 0 }, { 94, 0 }, { 95, 0 }, { 96, 0 }, { 97, 0 }, /* 85 - 89 */
+ { 98, 0 }, { 0, 115 }, { 0, 116 }, { 0, 117 }, { 102, 0 }, /* 90 - 94 */
+ { 103, 0 }, { 104, 0 }, { 105, 0 }, { 106, 0 }, { 107, 0 }, /* 95 - 99 */
+ { 108, 0 }, { 109, 0 }, { 110, 0 }, { 111, 0 }, { 112, 0 }, /* 100 - 104 */
+ { 113, 0 }, { 114, 0 }, { 115, 0 }, { 116, 0 }, { 117, 0 }, /* 105 - 109 */
+ { 118, 0 }, { 119, 0 }, { 120, 0 }, { 121, 0 }, { 122, 0 }, /* 110 - 114 */
+ { 123, 0 }, { 124, 0 }, { 125, 0 }, { 126, 0 }, { 127, 0 }, /* 115 - 119 */
+ { 128, 0 }, { 129, 0 }, { 130, 0 }, { 131, 0 }, { 132, 0 }, /* 120 - 124 */
+ { 133, 0 }, { 134, 0 }, { 135, 0 } /* 125 - 127 */
};
/*****************************************************************************/
-struct xrdp_key_info* APP_CC
-get_key_info_from_scan_code(int device_flags, int scan_code, int* keys,
+struct xrdp_key_info *APP_CC
+get_key_info_from_scan_code(int device_flags, int scan_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
- struct xrdp_keymap* keymap)
+ struct xrdp_keymap *keymap)
{
- struct xrdp_key_info* rv;
- int shift;
- int altgr;
- int ext;
- int index;
-
- ext = device_flags & KBD_FLAG_EXT; /* 0x0100 */
- shift = keys[42] || keys[54];
- altgr = keys[56] & KBD_FLAG_EXT; /* right alt */
- rv = 0;
- scan_code = scan_code & 0x7f;
- index = ext ? g_map[scan_code].code2 : g_map[scan_code].code1;
- /* keymap file is created with numlock off so we have to do this */
- if ((index >= 79) && (index <= 91))
- {
- if (num_lock)
+ struct xrdp_key_info *rv;
+ int shift;
+ int altgr;
+ int ext;
+ int index;
+
+ ext = device_flags &KBD_FLAG_EXT; /* 0x0100 */
+ shift = keys[42] || keys[54];
+ altgr = keys[56] &KBD_FLAG_EXT; /* right alt */
+ rv = 0;
+ scan_code = scan_code & 0x7f;
+ index = ext ? g_map[scan_code].code2 : g_map[scan_code].code1;
+
+ /* keymap file is created with numlock off so we have to do this */
+ if ((index >= 79) && (index <= 91))
+ {
+ if (num_lock)
+ {
+ rv = &(keymap->keys_shift[index]);
+ }
+ else
+ {
+ rv = &(keymap->keys_noshift[index]);
+ }
+ }
+ else if (shift && caps_lock)
+ {
+ rv = &(keymap->keys_shiftcapslock[index]);
+ }
+ else if (shift)
+ {
+ rv = &(keymap->keys_shift[index]);
+ }
+ else if (caps_lock)
+ {
+ rv = &(keymap->keys_capslock[index]);
+ }
+ else if (altgr)
{
- rv = &(keymap->keys_shift[index]);
+ rv = &(keymap->keys_altgr[index]);
}
else
{
- rv = &(keymap->keys_noshift[index]);
+ rv = &(keymap->keys_noshift[index]);
}
- }
- else if (shift && caps_lock)
- {
- rv = &(keymap->keys_shiftcapslock[index]);
- }
- else if (shift)
- {
- rv = &(keymap->keys_shift[index]);
- }
- else if (caps_lock)
- {
- rv = &(keymap->keys_capslock[index]);
- }
- else if (altgr)
- {
- rv = &(keymap->keys_altgr[index]);
- }
- else
- {
- rv = &(keymap->keys_noshift[index]);
- }
- return rv;
+
+ return rv;
}
/*****************************************************************************/
int APP_CC
-get_keysym_from_scan_code(int device_flags, int scan_code, int* keys,
+get_keysym_from_scan_code(int device_flags, int scan_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
- struct xrdp_keymap* keymap)
+ struct xrdp_keymap *keymap)
{
- struct xrdp_key_info* ki;
+ struct xrdp_key_info *ki;
- ki = get_key_info_from_scan_code(device_flags, scan_code, keys,
- caps_lock, num_lock, scroll_lock,
- keymap);
- if (ki == 0)
- {
- return 0;
- }
- return ki->sym;
+ ki = get_key_info_from_scan_code(device_flags, scan_code, keys,
+ caps_lock, num_lock, scroll_lock,
+ keymap);
+
+ if (ki == 0)
+ {
+ return 0;
+ }
+
+ return ki->sym;
}
/*****************************************************************************/
twchar APP_CC
-get_char_from_scan_code(int device_flags, int scan_code, int* keys,
+get_char_from_scan_code(int device_flags, int scan_code, int *keys,
int caps_lock, int num_lock, int scroll_lock,
- struct xrdp_keymap* keymap)
+ struct xrdp_keymap *keymap)
{
- struct xrdp_key_info* ki;
+ struct xrdp_key_info *ki;
- ki = get_key_info_from_scan_code(device_flags, scan_code, keys,
- caps_lock, num_lock, scroll_lock,
- keymap);
- if (ki == 0)
- {
- return 0;
- }
- return (twchar)(ki->chr);
+ ki = get_key_info_from_scan_code(device_flags, scan_code, keys,
+ caps_lock, num_lock, scroll_lock,
+ keymap);
+
+ if (ki == 0)
+ {
+ return 0;
+ }
+
+ return (twchar)(ki->chr);
}
/*****************************************************************************/
static int APP_CC
-km_read_section(int fd, const char* section_name, struct xrdp_key_info* keymap)
+km_read_section(int fd, const char *section_name, struct xrdp_key_info *keymap)
{
- struct list* names;
- struct list* values;
- int index;
- int code;
- int pos1;
- char* name;
- char* value;
-
- names = list_create();
- names->auto_free = 1;
- values = list_create();
- values->auto_free = 1;
- if (file_read_section(fd, section_name, names, values) == 0)
- {
- for (index = names->count - 1; index >= 0; index--)
+ struct list *names;
+ struct list *values;
+ int index;
+ int code;
+ int pos1;
+ char *name;
+ char *value;
+
+ names = list_create();
+ names->auto_free = 1;
+ values = list_create();
+ values->auto_free = 1;
+
+ if (file_read_section(fd, section_name, names, values) == 0)
{
- name = (char*)list_get_item(names, index);
- value = (char*)list_get_item(values, index);
- if ((name != 0) && (value != 0))
- {
- if (g_strncasecmp(name, "key", 3) == 0)
- {
- code = g_atoi(name + 3);
- }
- else
- {
- code = g_atoi(name);
- }
- if ((code >= 0) && (code < 256))
+ for (index = names->count - 1; index >= 0; index--)
{
- pos1 = g_pos(value, ":");
- if (pos1 >= 0)
- {
- keymap[code].chr = g_atoi(value + pos1 + 1);
- }
- keymap[code].sym = g_atoi(value);
+ name = (char *)list_get_item(names, index);
+ value = (char *)list_get_item(values, index);
+
+ if ((name != 0) && (value != 0))
+ {
+ if (g_strncasecmp(name, "key", 3) == 0)
+ {
+ code = g_atoi(name + 3);
+ }
+ else
+ {
+ code = g_atoi(name);
+ }
+
+ if ((code >= 0) && (code < 256))
+ {
+ pos1 = g_pos(value, ":");
+
+ if (pos1 >= 0)
+ {
+ keymap[code].chr = g_atoi(value + pos1 + 1);
+ }
+
+ keymap[code].sym = g_atoi(value);
+ }
+ }
}
- }
}
- }
- list_delete(names);
- list_delete(values);
- return 0;
+
+ list_delete(names);
+ list_delete(values);
+ return 0;
}
/*****************************************************************************/
int APP_CC
-get_keymaps(int keylayout, struct xrdp_keymap* keymap)
+get_keymaps(int keylayout, struct xrdp_keymap *keymap)
{
- int fd;
- char* filename;
- struct xrdp_keymap* lkeymap;
-
- filename = (char*)g_malloc(256, 0);
- /* check if there is a keymap file */
- g_snprintf(filename, 255, "%s/km-%4.4x.ini", XRDP_CFG_PATH, keylayout);
- /* if the file does not exist, try again with 'en-us' as fallback */
- if (!g_file_exist(filename))
- {
- g_snprintf(filename, 255, "%s/km-0409.ini", XRDP_CFG_PATH);
- }
- if (g_file_exist(filename))
- {
- fd = g_file_open(filename);
- if (fd > 0)
+ int fd;
+ char *filename;
+ struct xrdp_keymap *lkeymap;
+
+ filename = (char *)g_malloc(256, 0);
+ /* check if there is a keymap file */
+ g_snprintf(filename, 255, "%s/km-%4.4x.ini", XRDP_CFG_PATH, keylayout);
+
+ /* if the file does not exist, try again with 'en-us' as fallback */
+ if (!g_file_exist(filename))
+ {
+ g_snprintf(filename, 255, "%s/km-0409.ini", XRDP_CFG_PATH);
+ }
+
+ if (g_file_exist(filename))
+ {
+ fd = g_file_open(filename);
+
+ if (fd > 0)
+ {
+ lkeymap = (struct xrdp_keymap *)g_malloc(sizeof(struct xrdp_keymap), 0);
+ /* make a copy of the build in kaymap */
+ g_memcpy(lkeymap, keymap, sizeof(struct xrdp_keymap));
+ /* clear the keymaps */
+ g_memset(keymap, 0, sizeof(struct xrdp_keymap));
+ /* read the keymaps */
+ km_read_section(fd, "noshift", keymap->keys_noshift);
+ km_read_section(fd, "shift", keymap->keys_shift);
+ km_read_section(fd, "altgr", keymap->keys_altgr);
+ km_read_section(fd, "capslock", keymap->keys_capslock);
+ km_read_section(fd, "shiftcapslock", keymap->keys_shiftcapslock);
+
+ if (g_memcmp(lkeymap, keymap, sizeof(struct xrdp_keymap)) != 0)
+ {
+ log_message(LOG_LEVEL_WARNING,
+ "local keymap file for 0x%4.4x found and dosen't match "
+ "built in keymap, using local keymap file", keylayout);
+ }
+
+ g_free(lkeymap);
+ g_file_close(fd);
+ }
+ }
+ else
{
- lkeymap = (struct xrdp_keymap*)g_malloc(sizeof(struct xrdp_keymap), 0);
- /* make a copy of the build in kaymap */
- g_memcpy(lkeymap, keymap, sizeof(struct xrdp_keymap));
- /* clear the keymaps */
- g_memset(keymap, 0, sizeof(struct xrdp_keymap));
- /* read the keymaps */
- km_read_section(fd, "noshift", keymap->keys_noshift);
- km_read_section(fd, "shift", keymap->keys_shift);
- km_read_section(fd, "altgr", keymap->keys_altgr);
- km_read_section(fd, "capslock", keymap->keys_capslock);
- km_read_section(fd, "shiftcapslock", keymap->keys_shiftcapslock);
- if (g_memcmp(lkeymap, keymap, sizeof(struct xrdp_keymap)) != 0)
- {
- log_message(LOG_LEVEL_WARNING,
- "local keymap file for 0x%4.4x found and dosen't match "
- "built in keymap, using local keymap file", keylayout);
- }
- g_free(lkeymap);
- g_file_close(fd);
+ log_message(LOG_LEVEL_WARNING, "File does not exist: %s", filename);
}
- }
- else
- {
- log_message(LOG_LEVEL_WARNING,"File does not exist: %s",filename);
- }
- g_free(filename);
- return 0;
+
+ g_free(filename);
+ return 0;
}
diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c
index 4af8c4d7..0da7a101 100644
--- a/xrdp/xrdp.c
+++ b/xrdp/xrdp.c
@@ -1,31 +1,29 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2012
-
- main program
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * main program
+ */
#include "xrdp.h"
#include "log.h"
#define THREAD_WAITING 100
-static struct xrdp_listen* g_listen = 0;
+static struct xrdp_listen *g_listen = 0;
static long g_threadid = 0; /* main threadid */
static long g_sync_mutex = 0;
@@ -47,73 +45,77 @@ long APP_CC
g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,
long sync_param2)
{
- long sync_result;
- int sync_command;
-
- /* If the function is called from the main thread, the function can
- * be called directly. g_threadid= main thread ID*/
- if (tc_threadid_equal(tc_get_threadid(), g_threadid))
- {
- /* this is the main thread, call the function directly */
- /* in fork mode, this always happens too */
- sync_result = sync_func(sync_param1, sync_param2);
- /*g_writeln("g_xrdp_sync processed IN main thread -> continue");*/
- }
- else
- {
- /* All threads have to wait here until the main thread
- * process the function. g_process_waiting_function() is called
- * from the listening thread. g_process_waiting_function() process the function*/
- tc_mutex_lock(g_sync1_mutex);
- tc_mutex_lock(g_sync_mutex);
- g_sync_param1 = sync_param1;
- g_sync_param2 = sync_param2;
- g_sync_func = sync_func;
- /* set a value THREAD_WAITING so the g_process_waiting_function function
- * know if any function must be processed */
- g_sync_command = THREAD_WAITING;
- tc_mutex_unlock(g_sync_mutex);
- /* set this event so that the main thread know if
- * g_process_waiting_function() must be called */
- g_set_wait_obj(g_sync_event);
- do
+ long sync_result;
+ int sync_command;
+
+ /* If the function is called from the main thread, the function can
+ * be called directly. g_threadid= main thread ID*/
+ if (tc_threadid_equal(tc_get_threadid(), g_threadid))
{
- g_sleep(100);
- tc_mutex_lock(g_sync_mutex);
- /* load new value from global to see if the g_process_waiting_function()
- * function has processed the function */
- sync_command = g_sync_command;
- sync_result = g_sync_result;
- tc_mutex_unlock(g_sync_mutex);
+ /* this is the main thread, call the function directly */
+ /* in fork mode, this always happens too */
+ sync_result = sync_func(sync_param1, sync_param2);
+ /*g_writeln("g_xrdp_sync processed IN main thread -> continue");*/
}
- while (sync_command != 0); /* loop until g_process_waiting_function()
+ else
+ {
+ /* All threads have to wait here until the main thread
+ * process the function. g_process_waiting_function() is called
+ * from the listening thread. g_process_waiting_function() process the function*/
+ tc_mutex_lock(g_sync1_mutex);
+ tc_mutex_lock(g_sync_mutex);
+ g_sync_param1 = sync_param1;
+ g_sync_param2 = sync_param2;
+ g_sync_func = sync_func;
+ /* set a value THREAD_WAITING so the g_process_waiting_function function
+ * know if any function must be processed */
+ g_sync_command = THREAD_WAITING;
+ tc_mutex_unlock(g_sync_mutex);
+ /* set this event so that the main thread know if
+ * g_process_waiting_function() must be called */
+ g_set_wait_obj(g_sync_event);
+
+ do
+ {
+ g_sleep(100);
+ tc_mutex_lock(g_sync_mutex);
+ /* load new value from global to see if the g_process_waiting_function()
+ * function has processed the function */
+ sync_command = g_sync_command;
+ sync_result = g_sync_result;
+ tc_mutex_unlock(g_sync_mutex);
+ }
+ while (sync_command != 0); /* loop until g_process_waiting_function()
+
* has processed the request */
- tc_mutex_unlock(g_sync1_mutex);
- /*g_writeln("g_xrdp_sync processed BY main thread -> continue");*/
- }
- return sync_result;
+ tc_mutex_unlock(g_sync1_mutex);
+ /*g_writeln("g_xrdp_sync processed BY main thread -> continue");*/
+ }
+
+ return sync_result;
}
/*****************************************************************************/
void DEFAULT_CC
xrdp_shutdown(int sig)
{
- tbus threadid;
-
- threadid = tc_get_threadid();
- g_writeln("shutting down");
- g_writeln("signal %d threadid %p", sig, threadid);
- if (!g_is_wait_obj_set(g_term_event))
- {
- g_set_wait_obj(g_term_event);
- }
+ tbus threadid;
+
+ threadid = tc_get_threadid();
+ g_writeln("shutting down");
+ g_writeln("signal %d threadid %p", sig, threadid);
+
+ if (!g_is_wait_obj_set(g_term_event))
+ {
+ g_set_wait_obj(g_term_event);
+ }
}
/*****************************************************************************/
void DEFAULT_CC
xrdp_child(int sig)
{
- g_waitchild();
+ g_waitchild();
}
/*****************************************************************************/
@@ -121,61 +123,61 @@ xrdp_child(int sig)
int APP_CC
xrdp_child_fork(void)
{
- int pid;
- char text[256];
-
- /* close, don't delete these */
- g_close_wait_obj(g_term_event);
- g_close_wait_obj(g_sync_event);
- pid = g_getpid();
- g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
- g_term_event = g_create_wait_obj(text);
- g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
- g_sync_event = g_create_wait_obj(text);
- return 0;
+ int pid;
+ char text[256];
+
+ /* close, don't delete these */
+ g_close_wait_obj(g_term_event);
+ g_close_wait_obj(g_sync_event);
+ pid = g_getpid();
+ g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
+ g_term_event = g_create_wait_obj(text);
+ g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
+ g_sync_event = g_create_wait_obj(text);
+ return 0;
}
/*****************************************************************************/
int APP_CC
g_is_term(void)
{
- return g_is_wait_obj_set(g_term_event);
+ return g_is_wait_obj_set(g_term_event);
}
/*****************************************************************************/
void APP_CC
g_set_term(int in_val)
{
- if (in_val)
- {
- g_set_wait_obj(g_term_event);
- }
- else
- {
- g_reset_wait_obj(g_term_event);
- }
+ if (in_val)
+ {
+ g_set_wait_obj(g_term_event);
+ }
+ else
+ {
+ g_reset_wait_obj(g_term_event);
+ }
}
/*****************************************************************************/
tbus APP_CC
g_get_term_event(void)
{
- return g_term_event;
+ return g_term_event;
}
/*****************************************************************************/
tbus APP_CC
g_get_sync_event(void)
{
- return g_sync_event;
+ return g_sync_event;
}
/*****************************************************************************/
void DEFAULT_CC
pipe_sig(int sig_num)
{
- /* do nothing */
- g_writeln("got SIGPIPE(%d)", sig_num);
+ /* do nothing */
+ g_writeln("got SIGPIPE(%d)", sig_num);
}
/*****************************************************************************/
@@ -184,357 +186,400 @@ pipe_sig(int sig_num)
void APP_CC
g_process_waiting_function(void)
{
- tc_mutex_lock(g_sync_mutex);
- if (g_sync_command != 0)
- {
- if (g_sync_func != 0)
+ tc_mutex_lock(g_sync_mutex);
+
+ if (g_sync_command != 0)
{
- if (g_sync_command == THREAD_WAITING)
- {
- g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
- }
+ if (g_sync_func != 0)
+ {
+ if (g_sync_command == THREAD_WAITING)
+ {
+ g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
+ }
+ }
+
+ g_sync_command = 0;
}
- g_sync_command = 0;
- }
- tc_mutex_unlock(g_sync_mutex);
+
+ tc_mutex_unlock(g_sync_mutex);
}
/*****************************************************************************/
int APP_CC
-xrdp_process_params(int argc, char** argv,
- struct xrdp_startup_params* startup_params)
+xrdp_process_params(int argc, char **argv,
+ struct xrdp_startup_params *startup_params)
{
- int index;
- char option[128];
- char value[128];
-
- index = 1;
- while (index < argc)
- {
- g_strncpy(option, argv[index], 127);
- if (index + 1 < argc)
- {
- g_strncpy(value, argv[index + 1], 127);
- }
- else
- {
- value[0] = 0;
- }
- if ((g_strncasecmp(option, "-help", 255)) == 0 ||
- (g_strncasecmp(option, "--help", 255)) == 0 ||
- (g_strncasecmp(option, "-h", 255)) == 0)
- {
- startup_params->help = 1;
- }
- else if ((g_strncasecmp(option, "-kill", 255) == 0) ||
- (g_strncasecmp(option, "--kill", 255) == 0) ||
- (g_strncasecmp(option, "-k", 255) == 0))
- {
- startup_params->kill = 1;
- }
- else if ((g_strncasecmp(option, "-nodaemon", 255) == 0) ||
- (g_strncasecmp(option, "--nodaemon", 255) == 0) ||
- (g_strncasecmp(option, "-nd", 255) == 0) ||
- (g_strncasecmp(option, "--nd", 255) == 0) ||
- (g_strncasecmp(option, "-ns", 255) == 0) ||
- (g_strncasecmp(option, "--ns", 255) == 0))
- {
- startup_params->no_daemon = 1;
- }
- else if ((g_strncasecmp(option, "-v", 255) == 0) ||
- (g_strncasecmp(option, "--version", 255) == 0))
- {
- startup_params->version = 1;
- }
- else if ((g_strncasecmp(option, "-p", 255) == 0) ||
- (g_strncasecmp(option, "--port", 255) == 0))
- {
- index++;
- g_strncpy(startup_params->port, value, 127);
- if (g_strlen(startup_params->port) < 1)
- {
- g_writeln("error processing params, port [%s]", startup_params->port);
- return 1;
- }
- else
- {
- g_writeln("--port parameter found, ini override [%s]",
- startup_params->port);
- }
- }
- else if ((g_strncasecmp(option, "-f", 255) == 0) ||
- (g_strncasecmp(option, "--fork", 255) == 0))
- {
- startup_params->fork = 1;
- g_writeln("--fork parameter found, ini override");
- }
- else
+ int index;
+ char option[128];
+ char value[128];
+
+ index = 1;
+
+ while (index < argc)
{
- return 1;
+ g_strncpy(option, argv[index], 127);
+
+ if (index + 1 < argc)
+ {
+ g_strncpy(value, argv[index + 1], 127);
+ }
+ else
+ {
+ value[0] = 0;
+ }
+
+ if ((g_strncasecmp(option, "-help", 255)) == 0 ||
+ (g_strncasecmp(option, "--help", 255)) == 0 ||
+ (g_strncasecmp(option, "-h", 255)) == 0)
+ {
+ startup_params->help = 1;
+ }
+ else if ((g_strncasecmp(option, "-kill", 255) == 0) ||
+ (g_strncasecmp(option, "--kill", 255) == 0) ||
+ (g_strncasecmp(option, "-k", 255) == 0))
+ {
+ startup_params->kill = 1;
+ }
+ else if ((g_strncasecmp(option, "-nodaemon", 255) == 0) ||
+ (g_strncasecmp(option, "--nodaemon", 255) == 0) ||
+ (g_strncasecmp(option, "-nd", 255) == 0) ||
+ (g_strncasecmp(option, "--nd", 255) == 0) ||
+ (g_strncasecmp(option, "-ns", 255) == 0) ||
+ (g_strncasecmp(option, "--ns", 255) == 0))
+ {
+ startup_params->no_daemon = 1;
+ }
+ else if ((g_strncasecmp(option, "-v", 255) == 0) ||
+ (g_strncasecmp(option, "--version", 255) == 0))
+ {
+ startup_params->version = 1;
+ }
+ else if ((g_strncasecmp(option, "-p", 255) == 0) ||
+ (g_strncasecmp(option, "--port", 255) == 0))
+ {
+ index++;
+ g_strncpy(startup_params->port, value, 127);
+
+ if (g_strlen(startup_params->port) < 1)
+ {
+ g_writeln("error processing params, port [%s]", startup_params->port);
+ return 1;
+ }
+ else
+ {
+ g_writeln("--port parameter found, ini override [%s]",
+ startup_params->port);
+ }
+ }
+ else if ((g_strncasecmp(option, "-f", 255) == 0) ||
+ (g_strncasecmp(option, "--fork", 255) == 0))
+ {
+ startup_params->fork = 1;
+ g_writeln("--fork parameter found, ini override");
+ }
+ else
+ {
+ return 1;
+ }
+
+ index++;
}
- index++;
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-main(int argc, char** argv)
+main(int argc, char **argv)
{
- int test;
- int host_be;
- char cfg_file[256];
- enum logReturns error;
- struct xrdp_startup_params* startup_params;
- int pid;
- int fd;
- int no_daemon;
- char text[256];
- char pid_file[256];
-
- g_init("xrdp");
- ssl_init();
- /* check compiled endian with actual endian */
- test = 1;
- host_be = !((int)(*(unsigned char*)(&test)));
+ int test;
+ int host_be;
+ char cfg_file[256];
+ enum logReturns error;
+ struct xrdp_startup_params *startup_params;
+ int pid;
+ int fd;
+ int no_daemon;
+ char text[256];
+ char pid_file[256];
+
+ g_init("xrdp");
+ ssl_init();
+ /* check compiled endian with actual endian */
+ test = 1;
+ host_be = !((int)(*(unsigned char *)(&test)));
#if defined(B_ENDIAN)
- if (!host_be)
+
+ if (!host_be)
#endif
#if defined(L_ENDIAN)
- if (host_be)
+ if (host_be)
#endif
- {
- g_writeln("endian wrong, edit arch.h");
- return 0;
- }
- /* check long, int and void* sizes */
- if (sizeof(int) != 4)
- {
- g_writeln("unusable int size, must be 4");
- return 0;
- }
- if (sizeof(long) != sizeof(void*))
- {
- g_writeln("long size must match void* size");
- return 0;
- }
- if (sizeof(long) != 4 && sizeof(long) != 8)
- {
- g_writeln("unusable long size, must be 4 or 8");
- return 0;
- }
- if (sizeof(tui64) != 8)
- {
- g_writeln("unusable tui64 size, must be 8");
- return 0;
- }
- g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+ {
+ g_writeln("endian wrong, edit arch.h");
+ return 0;
+ }
- /* starting logging subsystem */
- error = log_start(cfg_file, "XRDP");
+ /* check long, int and void* sizes */
+ if (sizeof(int) != 4)
+ {
+ g_writeln("unusable int size, must be 4");
+ return 0;
+ }
- if (error != LOG_STARTUP_OK)
- {
- switch (error)
+ if (sizeof(long) != sizeof(void *))
{
- case LOG_ERROR_MALLOC:
- g_writeln("error on malloc. cannot start logging. quitting.");
- break;
- case LOG_ERROR_FILE_OPEN:
- g_writeln("error opening log file [%s]. quitting.",
- getLogFile(text, 255));
- break;
- default:
- g_writeln("log_start error");
- break;
+ g_writeln("long size must match void* size");
+ return 0;
}
- g_deinit();
- g_exit(1);
- }
-
- startup_params = (struct xrdp_startup_params*)
- g_malloc(sizeof(struct xrdp_startup_params), 1);
- if (xrdp_process_params(argc, argv, startup_params) != 0)
- {
- g_writeln("Unknown Parameter");
- g_writeln("xrdp -h for help");
- g_writeln("");
- g_deinit();
- g_exit(0);
- }
- g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH);
- no_daemon = 0;
+ if (sizeof(long) != 4 && sizeof(long) != 8)
+ {
+ g_writeln("unusable long size, must be 4 or 8");
+ return 0;
+ }
- if (startup_params->kill)
- {
- g_writeln("stopping xrdp");
- /* read the xrdp.pid file */
- fd = -1;
- if (g_file_exist(pid_file)) /* xrdp.pid */
+ if (sizeof(tui64) != 8)
+ {
+ g_writeln("unusable tui64 size, must be 8");
+ return 0;
+ }
+
+ g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+
+ /* starting logging subsystem */
+ error = log_start(cfg_file, "XRDP");
+
+ if (error != LOG_STARTUP_OK)
{
- fd = g_file_open(pid_file); /* xrdp.pid */
+ switch (error)
+ {
+ case LOG_ERROR_MALLOC:
+ g_writeln("error on malloc. cannot start logging. quitting.");
+ break;
+ case LOG_ERROR_FILE_OPEN:
+ g_writeln("error opening log file [%s]. quitting.",
+ getLogFile(text, 255));
+ break;
+ default:
+ g_writeln("log_start error");
+ break;
+ }
+
+ g_deinit();
+ g_exit(1);
}
- if (fd == -1)
+
+ startup_params = (struct xrdp_startup_params *)
+ g_malloc(sizeof(struct xrdp_startup_params), 1);
+
+ if (xrdp_process_params(argc, argv, startup_params) != 0)
{
- g_writeln("problem opening to xrdp.pid [%s]", pid_file);
- g_writeln("maybe its not running");
+ g_writeln("Unknown Parameter");
+ g_writeln("xrdp -h for help");
+ g_writeln("");
+ g_deinit();
+ g_exit(0);
}
- else
+
+ g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH);
+ no_daemon = 0;
+
+ if (startup_params->kill)
{
- g_memset(text, 0, 32);
- g_file_read(fd, text, 31);
- pid = g_atoi(text);
- g_writeln("stopping process id %d", pid);
- if (pid > 0)
- {
- g_sigterm(pid);
- }
- g_file_close(fd);
+ g_writeln("stopping xrdp");
+ /* read the xrdp.pid file */
+ fd = -1;
+
+ if (g_file_exist(pid_file)) /* xrdp.pid */
+ {
+ fd = g_file_open(pid_file); /* xrdp.pid */
+ }
+
+ if (fd == -1)
+ {
+ g_writeln("problem opening to xrdp.pid [%s]", pid_file);
+ g_writeln("maybe its not running");
+ }
+ else
+ {
+ g_memset(text, 0, 32);
+ g_file_read(fd, text, 31);
+ pid = g_atoi(text);
+ g_writeln("stopping process id %d", pid);
+
+ if (pid > 0)
+ {
+ g_sigterm(pid);
+ }
+
+ g_file_close(fd);
+ }
+
+ g_deinit();
+ g_exit(0);
}
- g_deinit();
- g_exit(0);
- }
- if (startup_params->no_daemon)
- {
- no_daemon = 1;
- }
- if (startup_params->help)
- {
- g_writeln("");
- g_writeln("xrdp: A Remote Desktop Protocol server.");
- g_writeln("Copyright (C) Jay Sorg 2004-2011");
- g_writeln("See http://xrdp.sourceforge.net for more information.");
- g_writeln("");
- g_writeln("Usage: xrdp [options]");
- g_writeln(" --help: show help");
- g_writeln(" --nodaemon: don't fork into background");
- g_writeln(" --kill: shut down xrdp");
- g_writeln(" --port: tcp listen port");
- g_writeln(" --fork: fork on new connection");
- g_writeln("");
- g_deinit();
- g_exit(0);
- }
- if (startup_params->version)
- {
- g_writeln("");
- g_writeln("xrdp: A Remote Desktop Protocol server.");
- g_writeln("Copyright (C) Jay Sorg 2004-2011");
- g_writeln("See http://xrdp.sourceforge.net for more information.");
- g_writeln("Version %s",PACKAGE_VERSION);
- g_writeln("");
- g_deinit();
- g_exit(0);
- }
- if (g_file_exist(pid_file)) /* xrdp.pid */
- {
- g_writeln("It looks like xrdp is allready running,");
- g_writeln("if not delete the xrdp.pid file and try again");
- g_deinit();
- g_exit(0);
- }
- if (!no_daemon)
- {
- /* make sure containing directory exists */
- g_create_path(pid_file);
+ if (startup_params->no_daemon)
+ {
+ no_daemon = 1;
+ }
- /* make sure we can write to pid file */
- fd = g_file_open(pid_file); /* xrdp.pid */
- if (fd == -1)
+ if (startup_params->help)
{
- g_writeln("running in daemon mode with no access to pid files, quitting");
- g_deinit();
- g_exit(0);
+ g_writeln("");
+ g_writeln("xrdp: A Remote Desktop Protocol server.");
+ g_writeln("Copyright (C) Jay Sorg 2004-2011");
+ g_writeln("See http://xrdp.sourceforge.net for more information.");
+ g_writeln("");
+ g_writeln("Usage: xrdp [options]");
+ g_writeln(" --help: show help");
+ g_writeln(" --nodaemon: don't fork into background");
+ g_writeln(" --kill: shut down xrdp");
+ g_writeln(" --port: tcp listen port");
+ g_writeln(" --fork: fork on new connection");
+ g_writeln("");
+ g_deinit();
+ g_exit(0);
}
- if (g_file_write(fd, "0", 1) == -1)
+
+ if (startup_params->version)
{
- g_writeln("running in daemon mode with no access to pid files, quitting");
- g_deinit();
- g_exit(0);
+ g_writeln("");
+ g_writeln("xrdp: A Remote Desktop Protocol server.");
+ g_writeln("Copyright (C) Jay Sorg 2004-2011");
+ g_writeln("See http://xrdp.sourceforge.net for more information.");
+ g_writeln("Version %s", PACKAGE_VERSION);
+ g_writeln("");
+ g_deinit();
+ g_exit(0);
}
- g_file_close(fd);
- g_file_delete(pid_file);
- }
- if (!no_daemon)
- {
- /* start of daemonizing code */
- pid = g_fork();
- if (pid == -1)
+
+ if (g_file_exist(pid_file)) /* xrdp.pid */
{
- g_writeln("problem forking");
- g_deinit();
- g_exit(1);
+ g_writeln("It looks like xrdp is allready running,");
+ g_writeln("if not delete the xrdp.pid file and try again");
+ g_deinit();
+ g_exit(0);
+ }
+
+ if (!no_daemon)
+ {
+
+ /* make sure containing directory exists */
+ g_create_path(pid_file);
+
+ /* make sure we can write to pid file */
+ fd = g_file_open(pid_file); /* xrdp.pid */
+
+ if (fd == -1)
+ {
+ g_writeln("running in daemon mode with no access to pid files, quitting");
+ g_deinit();
+ g_exit(0);
+ }
+
+ if (g_file_write(fd, "0", 1) == -1)
+ {
+ g_writeln("running in daemon mode with no access to pid files, quitting");
+ g_deinit();
+ g_exit(0);
+ }
+
+ g_file_close(fd);
+ g_file_delete(pid_file);
}
- if (0 != pid)
+
+ if (!no_daemon)
{
- g_writeln("process %d started ok", pid);
- /* exit, this is the main process */
- g_deinit();
- g_exit(0);
+ /* start of daemonizing code */
+ pid = g_fork();
+
+ if (pid == -1)
+ {
+ g_writeln("problem forking");
+ g_deinit();
+ g_exit(1);
+ }
+
+ if (0 != pid)
+ {
+ g_writeln("process %d started ok", pid);
+ /* exit, this is the main process */
+ g_deinit();
+ g_exit(0);
+ }
+
+ g_sleep(1000);
+ /* write the pid to file */
+ pid = g_getpid();
+ fd = g_file_open(pid_file); /* xrdp.pid */
+
+ if (fd == -1)
+ {
+ g_writeln("trying to write process id to xrdp.pid");
+ g_writeln("problem opening xrdp.pid");
+ g_writeln("maybe no rights");
+ }
+ else
+ {
+ g_sprintf(text, "%d", pid);
+ g_file_write(fd, text, g_strlen(text));
+ g_file_close(fd);
+ }
+
+ g_sleep(1000);
+ g_file_close(0);
+ g_file_close(1);
+ g_file_close(2);
+ g_file_open("/dev/null");
+ g_file_open("/dev/null");
+ g_file_open("/dev/null");
+ /* end of daemonizing code */
}
- g_sleep(1000);
- /* write the pid to file */
+
+ g_threadid = tc_get_threadid();
+ g_listen = xrdp_listen_create();
+ g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
+ g_signal_kill(xrdp_shutdown); /* SIGKILL */
+ g_signal_pipe(pipe_sig); /* SIGPIPE */
+ g_signal_terminate(xrdp_shutdown); /* SIGTERM */
+ g_signal_child_stop(xrdp_child); /* SIGCHLD */
+ g_sync_mutex = tc_mutex_create();
+ g_sync1_mutex = tc_mutex_create();
pid = g_getpid();
- fd = g_file_open(pid_file); /* xrdp.pid */
- if (fd == -1)
+ g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
+ g_term_event = g_create_wait_obj(text);
+
+ if (g_term_event == 0)
{
- g_writeln("trying to write process id to xrdp.pid");
- g_writeln("problem opening xrdp.pid");
- g_writeln("maybe no rights");
+ g_writeln("error creating g_term_event");
}
- else
+
+ g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
+ g_sync_event = g_create_wait_obj(text);
+
+ if (g_sync_event == 0)
{
- g_sprintf(text, "%d", pid);
- g_file_write(fd, text, g_strlen(text));
- g_file_close(fd);
+ g_writeln("error creating g_sync_event");
}
- g_sleep(1000);
- g_file_close(0);
- g_file_close(1);
- g_file_close(2);
- g_file_open("/dev/null");
- g_file_open("/dev/null");
- g_file_open("/dev/null");
- /* end of daemonizing code */
- }
- g_threadid = tc_get_threadid();
- g_listen = xrdp_listen_create();
- g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
- g_signal_kill(xrdp_shutdown); /* SIGKILL */
- g_signal_pipe(pipe_sig); /* SIGPIPE */
- g_signal_terminate(xrdp_shutdown); /* SIGTERM */
- g_signal_child_stop(xrdp_child); /* SIGCHLD */
- g_sync_mutex = tc_mutex_create();
- g_sync1_mutex = tc_mutex_create();
- pid = g_getpid();
- g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
- g_term_event = g_create_wait_obj(text);
- if (g_term_event == 0)
- {
- g_writeln("error creating g_term_event");
- }
- g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
- g_sync_event = g_create_wait_obj(text);
- if (g_sync_event == 0)
- {
- g_writeln("error creating g_sync_event");
- }
- g_listen->startup_params = startup_params;
- xrdp_listen_main_loop(g_listen);
- xrdp_listen_delete(g_listen);
- tc_mutex_delete(g_sync_mutex);
- tc_mutex_delete(g_sync1_mutex);
- g_delete_wait_obj(g_term_event);
- g_delete_wait_obj(g_sync_event);
- /* only main process should delete pid file */
- if ((!no_daemon) && (pid == g_getpid()))
- {
- /* delete the xrdp.pid file */
- g_file_delete(pid_file);
- }
- g_free(startup_params);
- g_deinit();
- return 0;
+
+ g_listen->startup_params = startup_params;
+ xrdp_listen_main_loop(g_listen);
+ xrdp_listen_delete(g_listen);
+ tc_mutex_delete(g_sync_mutex);
+ tc_mutex_delete(g_sync1_mutex);
+ g_delete_wait_obj(g_term_event);
+ g_delete_wait_obj(g_sync_event);
+
+ /* only main process should delete pid file */
+ if ((!no_daemon) && (pid == g_getpid()))
+ {
+ /* delete the xrdp.pid file */
+ g_file_delete(pid_file);
+ }
+
+ g_free(startup_params);
+ g_deinit();
+ return 0;
}
diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h
index 2f4e7eb6..a98acb16 100644
--- a/xrdp/xrdp.h
+++ b/xrdp/xrdp.h
@@ -1,24 +1,22 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- main include file
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * main include file
+ */
/* include other h files */
#if defined(HAVE_CONFIG_H)
diff --git a/xrdp/xrdp_bitmap.c b/xrdp/xrdp_bitmap.c
index 828c5139..d60cc920 100644
--- a/xrdp/xrdp_bitmap.c
+++ b/xrdp/xrdp_bitmap.c
@@ -1,27 +1,25 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- bitmap, drawable
- this is a object that can be drawn on with a painter
- all windows, bitmaps, even the screen are of this type
- maybe it should be called xrdp_drawable
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * bitmap, drawable
+ * this is a object that can be drawn on with a painter
+ * all windows, bitmaps, even the screen are of this type
+ * maybe it should be called xrdp_drawable
+ */
#include "xrdp.h"
#include "log.h"
@@ -29,303 +27,348 @@
static int g_crc_seed = 0xffffffff;
static int g_crc_table[256] =
{
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
- 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
- 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
- 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
- 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
- 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
- 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
- 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
- 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
- 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
- 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
- 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
- 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
- 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
- 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
- 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
- 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
- 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
- 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
- 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
- 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
#define CRC_START(in_crc) (in_crc) = g_crc_seed
#define CRC_PASS(in_pixel, in_crc) \
- (in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)
+ (in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)
#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ g_crc_seed)
/*****************************************************************************/
-struct xrdp_bitmap* APP_CC
+struct xrdp_bitmap *APP_CC
xrdp_bitmap_create(int width, int height, int bpp,
- int type, struct xrdp_wm* wm)
+ int type, struct xrdp_wm *wm)
{
- struct xrdp_bitmap* self = (struct xrdp_bitmap *)NULL;
- int Bpp = 0;
-
- self = (struct xrdp_bitmap*)g_malloc(sizeof(struct xrdp_bitmap), 1);
- self->type = type;
- self->width = width;
- self->height = height;
- self->bpp = bpp;
- Bpp = 4;
- switch (bpp)
- {
- case 8: Bpp = 1; break;
- case 15: Bpp = 2; break;
- case 16: Bpp = 2; break;
- }
- if (self->type == WND_TYPE_BITMAP || self->type == WND_TYPE_IMAGE)
- {
- self->data = (char*)g_malloc(width * height * Bpp, 0);
- }
- if (self->type != WND_TYPE_BITMAP)
- {
- self->child_list = list_create();
- }
- self->line_size = width * Bpp;
- if (self->type == WND_TYPE_COMBO)
- {
- self->string_list = list_create();
- self->string_list->auto_free = 1;
- self->data_list = list_create();
- self->data_list->auto_free = 1;
- }
- self->wm = wm;
- return self;
+ struct xrdp_bitmap *self = (struct xrdp_bitmap *)NULL;
+ int Bpp = 0;
+
+ self = (struct xrdp_bitmap *)g_malloc(sizeof(struct xrdp_bitmap), 1);
+ self->type = type;
+ self->width = width;
+ self->height = height;
+ self->bpp = bpp;
+ Bpp = 4;
+
+ switch (bpp)
+ {
+ case 8:
+ Bpp = 1;
+ break;
+ case 15:
+ Bpp = 2;
+ break;
+ case 16:
+ Bpp = 2;
+ break;
+ }
+
+ if (self->type == WND_TYPE_BITMAP || self->type == WND_TYPE_IMAGE)
+ {
+ self->data = (char *)g_malloc(width * height * Bpp, 0);
+ }
+
+ if (self->type != WND_TYPE_BITMAP)
+ {
+ self->child_list = list_create();
+ }
+
+ self->line_size = width *Bpp;
+
+ if (self->type == WND_TYPE_COMBO)
+ {
+ self->string_list = list_create();
+ self->string_list->auto_free = 1;
+ self->data_list = list_create();
+ self->data_list->auto_free = 1;
+ }
+
+ self->wm = wm;
+ return self;
}
/*****************************************************************************/
-struct xrdp_bitmap* APP_CC
+struct xrdp_bitmap *APP_CC
xrdp_bitmap_create_with_data(int width, int height,
- int bpp, char* data,
- struct xrdp_wm* wm)
+ int bpp, char *data,
+ struct xrdp_wm *wm)
{
- struct xrdp_bitmap* self = (struct xrdp_bitmap *)NULL;
-
- self = (struct xrdp_bitmap*)g_malloc(sizeof(struct xrdp_bitmap), 1);
- self->type = WND_TYPE_BITMAP;
- self->width = width;
- self->height = height;
- self->bpp = bpp;
- self->data = data;
- self->do_not_free_data = 1;
- self->wm = wm;
- return self;
+ struct xrdp_bitmap *self = (struct xrdp_bitmap *)NULL;
+
+ self = (struct xrdp_bitmap *)g_malloc(sizeof(struct xrdp_bitmap), 1);
+ self->type = WND_TYPE_BITMAP;
+ self->width = width;
+ self->height = height;
+ self->bpp = bpp;
+ self->data = data;
+ self->do_not_free_data = 1;
+ self->wm = wm;
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_bitmap_delete(struct xrdp_bitmap* self)
+xrdp_bitmap_delete(struct xrdp_bitmap *self)
{
- int i = 0;
- struct xrdp_mod_data* mod_data = (struct xrdp_mod_data *)NULL;
+ int i = 0;
+ struct xrdp_mod_data *mod_data = (struct xrdp_mod_data *)NULL;
- if (self == 0)
- {
- return;
- }
- if (self->wm != 0)
- {
- if (self->wm->focused_window != 0)
+ if (self == 0)
{
- if (self->wm->focused_window->focused_control == self)
- {
- self->wm->focused_window->focused_control = 0;
- }
+ return;
}
- if (self->wm->focused_window == self)
- {
- self->wm->focused_window = 0;
- }
- if (self->wm->dragging_window == self)
- {
- self->wm->dragging_window = 0;
- }
- if (self->wm->button_down == self)
- {
- self->wm->button_down = 0;
- }
- if (self->wm->popup_wnd == self)
+
+ if (self->wm != 0)
{
- self->wm->popup_wnd = 0;
+ if (self->wm->focused_window != 0)
+ {
+ if (self->wm->focused_window->focused_control == self)
+ {
+ self->wm->focused_window->focused_control = 0;
+ }
+ }
+
+ if (self->wm->focused_window == self)
+ {
+ self->wm->focused_window = 0;
+ }
+
+ if (self->wm->dragging_window == self)
+ {
+ self->wm->dragging_window = 0;
+ }
+
+ if (self->wm->button_down == self)
+ {
+ self->wm->button_down = 0;
+ }
+
+ if (self->wm->popup_wnd == self)
+ {
+ self->wm->popup_wnd = 0;
+ }
+
+ if (self->wm->login_window == self)
+ {
+ self->wm->login_window = 0;
+ }
+
+ if (self->wm->log_wnd == self)
+ {
+ self->wm->log_wnd = 0;
+ }
}
- if (self->wm->login_window == self)
+
+ if (self->child_list != 0)
{
- self->wm->login_window = 0;
+ for (i = self->child_list->count - 1; i >= 0; i--)
+ {
+ xrdp_bitmap_delete((struct xrdp_bitmap *)self->child_list->items[i]);
+ }
+
+ list_delete(self->child_list);
}
- if (self->wm->log_wnd == self)
+
+ if (self->parent != 0)
{
- self->wm->log_wnd = 0;
+ i = list_index_of(self->parent->child_list, (long)self);
+
+ if (i >= 0)
+ {
+ list_remove_item(self->parent->child_list, i);
+ }
}
- }
- if (self->child_list != 0)
- {
- for (i = self->child_list->count - 1; i >= 0; i--)
+
+ if (self->string_list != 0) /* for combo */
{
- xrdp_bitmap_delete((struct xrdp_bitmap*)self->child_list->items[i]);
+ list_delete(self->string_list);
}
- list_delete(self->child_list);
- }
- if (self->parent != 0)
- {
- i = list_index_of(self->parent->child_list, (long)self);
- if (i >= 0)
+
+ if (self->data_list != 0) /* for combo */
{
- list_remove_item(self->parent->child_list, i);
+ for (i = 0; i < self->data_list->count; i++)
+ {
+ mod_data = (struct xrdp_mod_data *)list_get_item(self->data_list, i);
+
+ if (mod_data != 0)
+ {
+ list_delete(mod_data->names);
+ list_delete(mod_data->values);
+ }
+ }
+
+ list_delete(self->data_list);
}
- }
- if (self->string_list != 0) /* for combo */
- {
- list_delete(self->string_list);
- }
- if (self->data_list != 0) /* for combo */
- {
- for (i = 0; i < self->data_list->count; i++)
+
+ if (!self->do_not_free_data)
{
- mod_data = (struct xrdp_mod_data*)list_get_item(self->data_list, i);
- if (mod_data != 0)
- {
- list_delete(mod_data->names);
- list_delete(mod_data->values);
- }
+ g_free(self->data);
}
- list_delete(self->data_list);
- }
- if (!self->do_not_free_data)
- {
- g_free(self->data);
- }
- g_free(self->caption1);
- g_free(self);
+
+ g_free(self->caption1);
+ g_free(self);
}
/*****************************************************************************/
-struct xrdp_bitmap* APP_CC
-xrdp_bitmap_get_child_by_id(struct xrdp_bitmap* self, int id)
+struct xrdp_bitmap *APP_CC
+xrdp_bitmap_get_child_by_id(struct xrdp_bitmap *self, int id)
{
- int i = 0;
- struct xrdp_bitmap* b = (struct xrdp_bitmap *)NULL;
+ int i = 0;
+ struct xrdp_bitmap *b = (struct xrdp_bitmap *)NULL;
- for (i = 0; i < self->child_list->count; i++)
- {
- b = (struct xrdp_bitmap*)list_get_item(self->child_list, i);
- if (b->id == id)
+ for (i = 0; i < self->child_list->count; i++)
{
- return b;
+ b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);
+
+ if (b->id == id)
+ {
+ return b;
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* if focused is true focus this window else unfocus it */
/* returns error */
int APP_CC
-xrdp_bitmap_set_focus(struct xrdp_bitmap* self, int focused)
+xrdp_bitmap_set_focus(struct xrdp_bitmap *self, int focused)
{
- struct xrdp_painter* painter = (struct xrdp_painter *)NULL;
+ struct xrdp_painter *painter = (struct xrdp_painter *)NULL;
- if (self == 0)
- {
- return 0;
- }
- if (self->type != WND_TYPE_WND) /* 1 */
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (self->type != WND_TYPE_WND) /* 1 */
+ {
+ return 0;
+ }
+
+ painter = xrdp_painter_create(self->wm, self->wm->session);
+ xrdp_painter_font_needed(painter);
+ xrdp_painter_begin_update(painter);
+
+ if (focused)
+ {
+ /* active title bar */
+ painter->fg_color = self->wm->blue;
+ xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
+ painter->fg_color = self->wm->white;
+ }
+ else
+ {
+ /* inactive title bar */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
+ painter->fg_color = self->wm->black;
+ }
+
+ xrdp_painter_draw_text(painter, self, 4, 4, self->caption1);
+ xrdp_painter_end_update(painter);
+ xrdp_painter_delete(painter);
return 0;
- }
- painter = xrdp_painter_create(self->wm, self->wm->session);
- xrdp_painter_font_needed(painter);
- xrdp_painter_begin_update(painter);
- if (focused)
- {
- /* active title bar */
- painter->fg_color = self->wm->blue;
- xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
- painter->fg_color = self->wm->white;
- }
- else
- {
- /* inactive title bar */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
- painter->fg_color = self->wm->black;
- }
- xrdp_painter_draw_text(painter, self, 4, 4, self->caption1);
- xrdp_painter_end_update(painter);
- xrdp_painter_delete(painter);
- return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_bitmap_get_index(struct xrdp_bitmap* self, int* palette, int color)
+xrdp_bitmap_get_index(struct xrdp_bitmap *self, int *palette, int color)
{
- int r = 0;
- int g = 0;
- int b = 0;
-
- r = (color & 0xff0000) >> 16;
- g = (color & 0x00ff00) >> 8;
- b = (color & 0x0000ff) >> 0;
- r = (r >> 5) << 0;
- g = (g >> 5) << 3;
- b = (b >> 6) << 6;
- return (b | g | r);
+ int r = 0;
+ int g = 0;
+ int b = 0;
+
+ r = (color & 0xff0000) >> 16;
+ g = (color & 0x00ff00) >> 8;
+ b = (color & 0x0000ff) >> 0;
+ r = (r >> 5) << 0;
+ g = (g >> 5) << 3;
+ b = (b >> 6) << 6;
+ return (b | g | r);
}
/*****************************************************************************/
/* returns error */
int APP_CC
-xrdp_bitmap_resize(struct xrdp_bitmap* self, int width, int height)
+xrdp_bitmap_resize(struct xrdp_bitmap *self, int width, int height)
{
- int Bpp = 0;
+ int Bpp = 0;
+
+ if ((width == self->width) && (height == self->height))
+ {
+ return 0;
+ }
+
+ if (self->do_not_free_data)
+ {
+ return 1;
+ }
+
+ self->width = width;
+ self->height = height;
+ Bpp = 4;
- if ((width == self->width) && (height == self->height))
- {
+ switch (self->bpp)
+ {
+ case 8:
+ Bpp = 1;
+ break;
+ case 15:
+ Bpp = 2;
+ break;
+ case 16:
+ Bpp = 2;
+ break;
+ }
+
+ g_free(self->data);
+ self->data = (char *)g_malloc(width * height * Bpp, 0);
+ self->line_size = width * Bpp;
return 0;
- }
- if (self->do_not_free_data)
- {
- return 1;
- }
- self->width = width;
- self->height = height;
- Bpp = 4;
- switch (self->bpp)
- {
- case 8: Bpp = 1; break;
- case 15: Bpp = 2; break;
- case 16: Bpp = 2; break;
- }
- g_free(self->data);
- self->data = (char*)g_malloc(width * height * Bpp, 0);
- self->line_size = width * Bpp;
- return 0;
}
/*****************************************************************************/
@@ -333,1428 +376,1569 @@ xrdp_bitmap_resize(struct xrdp_bitmap* self, int width, int height)
/* return 0 ok */
/* return 1 error */
int APP_CC
-xrdp_bitmap_load(struct xrdp_bitmap* self, const char* filename, int* palette)
+xrdp_bitmap_load(struct xrdp_bitmap *self, const char *filename, int *palette)
{
- int fd = 0;
- int i = 0;
- int j = 0;
- int k = 0;
- int color = 0;
- int size = 0;
- int palette1[256];
- char type1[4];
- struct xrdp_bmp_header header;
- struct stream* s = (struct stream *)NULL;
-
- g_memset(palette1,0,sizeof(int) * 256);
- g_memset(type1,0,sizeof(char) * 4);
- g_memset(&header,0,sizeof(struct xrdp_bmp_header));
-
- if (!g_file_exist(filename))
- {
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
- "does not exist", filename);
- return 1;
- }
- s = (struct stream *)NULL;
- fd = g_file_open(filename);
- if (fd != -1)
- {
- /* read file type */
- if (g_file_read(fd, type1, 2) != 2)
- {
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
- "read error", filename);
- g_file_close(fd);
- return 1;
- }
- if ((type1[0] != 'B') || (type1[1] != 'M'))
- {
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
- "not BMP file", filename);
- g_file_close(fd);
- return 1;
- }
- /* read file size */
- make_stream(s);
- init_stream(s, 8192);
- g_file_read(fd, s->data, 4);
- in_uint32_le(s, size);
- /* read bmp header */
- g_file_seek(fd, 14);
- init_stream(s, 8192);
- g_file_read(fd, s->data, 40); /* size better be 40 */
- in_uint32_le(s, header.size);
- in_uint32_le(s, header.image_width);
- in_uint32_le(s, header.image_height);
- in_uint16_le(s, header.planes);
- in_uint16_le(s, header.bit_count);
- in_uint32_le(s, header.compression);
- in_uint32_le(s, header.image_size);
- in_uint32_le(s, header.x_pels_per_meter);
- in_uint32_le(s, header.y_pels_per_meter);
- in_uint32_le(s, header.clr_used);
- in_uint32_le(s, header.clr_important);
- if ((header.bit_count != 4) && (header.bit_count != 8) &&
- (header.bit_count != 24))
- {
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
- "bad bpp %d", filename, header.bit_count);
- free_stream(s);
- g_file_close(fd);
- return 1;
- }
- if (header.bit_count == 24) /* 24 bit bitmap */
- {
- g_file_seek(fd, 14 + header.size);
- xrdp_bitmap_resize(self, header.image_width, header.image_height);
- size = header.image_width * header.image_height * 3;
- init_stream(s, size);
- /* read data */
- for (i = header.image_height - 1; i >= 0; i--)
- {
- size = header.image_width * 3;
- k = g_file_read(fd, s->data + i * size, size);
- if (k != size)
+ int fd = 0;
+ int i = 0;
+ int j = 0;
+ int k = 0;
+ int color = 0;
+ int size = 0;
+ int palette1[256];
+ char type1[4];
+ struct xrdp_bmp_header header;
+ struct stream *s = (struct stream *)NULL;
+
+ g_memset(palette1, 0, sizeof(int) * 256);
+ g_memset(type1, 0, sizeof(char) * 4);
+ g_memset(&header, 0, sizeof(struct xrdp_bmp_header));
+
+ if (!g_file_exist(filename))
+ {
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
+ "does not exist", filename);
+ return 1;
+ }
+
+ s = (struct stream *)NULL;
+ fd = g_file_open(filename);
+
+ if (fd != -1)
+ {
+ /* read file type */
+ if (g_file_read(fd, type1, 2) != 2)
{
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap "
- "file [%s] read", filename);
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
+ "read error", filename);
+ g_file_close(fd);
+ return 1;
}
- }
- for (i = 0; i < self->height; i++)
- {
- for (j = 0; j < self->width; j++)
+
+ if ((type1[0] != 'B') || (type1[1] != 'M'))
{
- in_uint8(s, k);
- color = k;
- in_uint8(s, k);
- color |= k << 8;
- in_uint8(s, k);
- color |= k << 16;
- if (self->bpp == 8)
- {
- color = xrdp_bitmap_get_index(self, palette, color);
- }
- else if (self->bpp == 15)
- {
- color = COLOR15((color & 0xff0000) >> 16,
- (color & 0x00ff00) >> 8,
- (color & 0x0000ff) >> 0);
- }
- else if (self->bpp == 16)
- {
- color = COLOR16((color & 0xff0000) >> 16,
- (color & 0x00ff00) >> 8,
- (color & 0x0000ff) >> 0);
- }
- xrdp_bitmap_set_pixel(self, j, i, color);
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
+ "not BMP file", filename);
+ g_file_close(fd);
+ return 1;
}
- }
- }
- else if (header.bit_count == 8) /* 8 bit bitmap */
- {
- /* read palette */
- g_file_seek(fd, 14 + header.size);
- init_stream(s, 8192);
- g_file_read(fd, s->data, header.clr_used * sizeof(int));
- for (i = 0; i < header.clr_used; i++)
- {
- in_uint32_le(s, palette1[i]);
- }
- xrdp_bitmap_resize(self, header.image_width, header.image_height);
- size = header.image_width * header.image_height;
- init_stream(s, size);
- /* read data */
- for (i = header.image_height - 1; i >= 0; i--)
- {
- size = header.image_width;
- k = g_file_read(fd, s->data + i * size, size);
- if (k != size)
+
+ /* read file size */
+ make_stream(s);
+ init_stream(s, 8192);
+ g_file_read(fd, s->data, 4);
+ in_uint32_le(s, size);
+ /* read bmp header */
+ g_file_seek(fd, 14);
+ init_stream(s, 8192);
+ g_file_read(fd, s->data, 40); /* size better be 40 */
+ in_uint32_le(s, header.size);
+ in_uint32_le(s, header.image_width);
+ in_uint32_le(s, header.image_height);
+ in_uint16_le(s, header.planes);
+ in_uint16_le(s, header.bit_count);
+ in_uint32_le(s, header.compression);
+ in_uint32_le(s, header.image_size);
+ in_uint32_le(s, header.x_pels_per_meter);
+ in_uint32_le(s, header.y_pels_per_meter);
+ in_uint32_le(s, header.clr_used);
+ in_uint32_le(s, header.clr_important);
+
+ if ((header.bit_count != 4) && (header.bit_count != 8) &&
+ (header.bit_count != 24))
{
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap "
- "file [%s] read", filename);
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap file [%s] "
+ "bad bpp %d", filename, header.bit_count);
+ free_stream(s);
+ g_file_close(fd);
+ return 1;
}
- }
- for (i = 0; i < self->height; i++)
- {
- for (j = 0; j < self->width; j++)
+
+ if (header.bit_count == 24) /* 24 bit bitmap */
{
- in_uint8(s, k);
- color = palette1[k];
- if (self->bpp == 8)
- {
- color = xrdp_bitmap_get_index(self, palette, color);
- }
- else if (self->bpp == 15)
- {
- color = COLOR15((color & 0xff0000) >> 16,
- (color & 0x00ff00) >> 8,
- (color & 0x0000ff) >> 0);
- }
- else if (self->bpp == 16)
- {
- color = COLOR16((color & 0xff0000) >> 16,
- (color & 0x00ff00) >> 8,
- (color & 0x0000ff) >> 0);
- }
- xrdp_bitmap_set_pixel(self, j, i, color);
+ g_file_seek(fd, 14 + header.size);
+ xrdp_bitmap_resize(self, header.image_width, header.image_height);
+ size = header.image_width * header.image_height * 3;
+ init_stream(s, size);
+
+ /* read data */
+ for (i = header.image_height - 1; i >= 0; i--)
+ {
+ size = header.image_width * 3;
+ k = g_file_read(fd, s->data + i * size, size);
+
+ if (k != size)
+ {
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap "
+ "file [%s] read", filename);
+ }
+ }
+
+ for (i = 0; i < self->height; i++)
+ {
+ for (j = 0; j < self->width; j++)
+ {
+ in_uint8(s, k);
+ color = k;
+ in_uint8(s, k);
+ color |= k << 8;
+ in_uint8(s, k);
+ color |= k << 16;
+
+ if (self->bpp == 8)
+ {
+ color = xrdp_bitmap_get_index(self, palette, color);
+ }
+ else if (self->bpp == 15)
+ {
+ color = COLOR15((color & 0xff0000) >> 16,
+ (color & 0x00ff00) >> 8,
+ (color & 0x0000ff) >> 0);
+ }
+ else if (self->bpp == 16)
+ {
+ color = COLOR16((color & 0xff0000) >> 16,
+ (color & 0x00ff00) >> 8,
+ (color & 0x0000ff) >> 0);
+ }
+
+ xrdp_bitmap_set_pixel(self, j, i, color);
+ }
+ }
}
- }
- }
- else if (header.bit_count == 4) /* 4 bit bitmap */
- {
- /* read palette */
- g_file_seek(fd, 14 + header.size);
- init_stream(s, 8192);
- g_file_read(fd, s->data, header.clr_used * sizeof(int));
- for (i = 0; i < header.clr_used; i++)
- {
- in_uint32_le(s, palette1[i]);
- }
- xrdp_bitmap_resize(self, header.image_width, header.image_height);
- size = (header.image_width * header.image_height) / 2;
- init_stream(s, size);
- /* read data */
- for (i = header.image_height - 1; i >= 0; i--)
- {
- size = header.image_width / 2;
- k = g_file_read(fd, s->data + i * size, size);
- if (k != size)
+ else if (header.bit_count == 8) /* 8 bit bitmap */
{
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap "
- "file [%s] read", filename);
+ /* read palette */
+ g_file_seek(fd, 14 + header.size);
+ init_stream(s, 8192);
+ g_file_read(fd, s->data, header.clr_used * sizeof(int));
+
+ for (i = 0; i < header.clr_used; i++)
+ {
+ in_uint32_le(s, palette1[i]);
+ }
+
+ xrdp_bitmap_resize(self, header.image_width, header.image_height);
+ size = header.image_width * header.image_height;
+ init_stream(s, size);
+
+ /* read data */
+ for (i = header.image_height - 1; i >= 0; i--)
+ {
+ size = header.image_width;
+ k = g_file_read(fd, s->data + i * size, size);
+
+ if (k != size)
+ {
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap "
+ "file [%s] read", filename);
+ }
+ }
+
+ for (i = 0; i < self->height; i++)
+ {
+ for (j = 0; j < self->width; j++)
+ {
+ in_uint8(s, k);
+ color = palette1[k];
+
+ if (self->bpp == 8)
+ {
+ color = xrdp_bitmap_get_index(self, palette, color);
+ }
+ else if (self->bpp == 15)
+ {
+ color = COLOR15((color & 0xff0000) >> 16,
+ (color & 0x00ff00) >> 8,
+ (color & 0x0000ff) >> 0);
+ }
+ else if (self->bpp == 16)
+ {
+ color = COLOR16((color & 0xff0000) >> 16,
+ (color & 0x00ff00) >> 8,
+ (color & 0x0000ff) >> 0);
+ }
+
+ xrdp_bitmap_set_pixel(self, j, i, color);
+ }
+ }
}
- }
- for (i = 0; i < self->height; i++)
- {
- for (j = 0; j < self->width; j++)
+ else if (header.bit_count == 4) /* 4 bit bitmap */
{
- if ((j & 1) == 0)
- {
- in_uint8(s, k);
- color = (k >> 4) & 0xf;
- }
- else
- {
- color = k & 0xf;
- }
- color = palette1[color];
- if (self->bpp == 8)
- {
- color = xrdp_bitmap_get_index(self, palette, color);
- }
- else if (self->bpp == 15)
- {
- color = COLOR15((color & 0xff0000) >> 16,
- (color & 0x00ff00) >> 8,
- (color & 0x0000ff) >> 0);
- }
- else if (self->bpp == 16)
- {
- color = COLOR16((color & 0xff0000) >> 16,
- (color & 0x00ff00) >> 8,
- (color & 0x0000ff) >> 0);
- }
- xrdp_bitmap_set_pixel(self, j, i, color);
+ /* read palette */
+ g_file_seek(fd, 14 + header.size);
+ init_stream(s, 8192);
+ g_file_read(fd, s->data, header.clr_used * sizeof(int));
+
+ for (i = 0; i < header.clr_used; i++)
+ {
+ in_uint32_le(s, palette1[i]);
+ }
+
+ xrdp_bitmap_resize(self, header.image_width, header.image_height);
+ size = (header.image_width * header.image_height) / 2;
+ init_stream(s, size);
+
+ /* read data */
+ for (i = header.image_height - 1; i >= 0; i--)
+ {
+ size = header.image_width / 2;
+ k = g_file_read(fd, s->data + i * size, size);
+
+ if (k != size)
+ {
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error bitmap "
+ "file [%s] read", filename);
+ }
+ }
+
+ for (i = 0; i < self->height; i++)
+ {
+ for (j = 0; j < self->width; j++)
+ {
+ if ((j & 1) == 0)
+ {
+ in_uint8(s, k);
+ color = (k >> 4) & 0xf;
+ }
+ else
+ {
+ color = k & 0xf;
+ }
+
+ color = palette1[color];
+
+ if (self->bpp == 8)
+ {
+ color = xrdp_bitmap_get_index(self, palette, color);
+ }
+ else if (self->bpp == 15)
+ {
+ color = COLOR15((color & 0xff0000) >> 16,
+ (color & 0x00ff00) >> 8,
+ (color & 0x0000ff) >> 0);
+ }
+ else if (self->bpp == 16)
+ {
+ color = COLOR16((color & 0xff0000) >> 16,
+ (color & 0x00ff00) >> 8,
+ (color & 0x0000ff) >> 0);
+ }
+
+ xrdp_bitmap_set_pixel(self, j, i, color);
+ }
+ }
}
- }
- }
- g_file_close(fd);
- free_stream(s);
- }
- else
- {
- log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error loading bitmap "
- "from file [%s]", filename);
- return 1;
- }
- return 0;
+
+ g_file_close(fd);
+ free_stream(s);
+ }
+ else
+ {
+ log_message(LOG_LEVEL_ERROR, "xrdp_bitmap_load: error loading bitmap "
+ "from file [%s]", filename);
+ return 1;
+ }
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_bitmap_get_pixel(struct xrdp_bitmap* self, int x, int y)
+xrdp_bitmap_get_pixel(struct xrdp_bitmap *self, int x, int y)
{
- if (self == 0)
- {
- return 0;
- }
- if (self->data == 0)
- {
- return 0;
- }
- if (x >= 0 && x < self->width && y >= 0 && y < self->height)
- {
- if (self->bpp == 8)
+ if (self == 0)
{
- return GETPIXEL8(self->data, x, y, self->width);
+ return 0;
}
- else if (self->bpp == 15 || self->bpp == 16)
+
+ if (self->data == 0)
{
- return GETPIXEL16(self->data, x, y, self->width);
+ return 0;
}
- else if (self->bpp == 24)
+
+ if (x >= 0 && x < self->width && y >= 0 && y < self->height)
{
- return GETPIXEL32(self->data, x, y, self->width);
+ if (self->bpp == 8)
+ {
+ return GETPIXEL8(self->data, x, y, self->width);
+ }
+ else if (self->bpp == 15 || self->bpp == 16)
+ {
+ return GETPIXEL16(self->data, x, y, self->width);
+ }
+ else if (self->bpp == 24)
+ {
+ return GETPIXEL32(self->data, x, y, self->width);
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_bitmap_set_pixel(struct xrdp_bitmap* self, int x, int y, int pixel)
+xrdp_bitmap_set_pixel(struct xrdp_bitmap *self, int x, int y, int pixel)
{
- if (self == 0)
- {
- return 0;
- }
- if (self->data == 0)
- {
- return 0;
- }
- if (x >= 0 && x < self->width && y >= 0 && y < self->height)
- {
- if (self->bpp == 8)
+ if (self == 0)
{
- SETPIXEL8(self->data, x, y, self->width, pixel);
+ return 0;
}
- else if (self->bpp == 15 || self->bpp == 16)
+
+ if (self->data == 0)
{
- SETPIXEL16(self->data, x, y, self->width, pixel);
+ return 0;
}
- else if (self->bpp == 24)
+
+ if (x >= 0 && x < self->width && y >= 0 && y < self->height)
{
- SETPIXEL32(self->data, x, y, self->width, pixel);
+ if (self->bpp == 8)
+ {
+ SETPIXEL8(self->data, x, y, self->width, pixel);
+ }
+ else if (self->bpp == 15 || self->bpp == 16)
+ {
+ SETPIXEL16(self->data, x, y, self->width, pixel);
+ }
+ else if (self->bpp == 24)
+ {
+ SETPIXEL32(self->data, x, y, self->width, pixel);
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* copy part of self at x, y to 0, 0 in dest */
/* returns error */
int APP_CC
-xrdp_bitmap_copy_box(struct xrdp_bitmap* self,
- struct xrdp_bitmap* dest,
+xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
+ struct xrdp_bitmap *dest,
int x, int y, int cx, int cy)
{
- int i = 0;
- int j = 0;
- int destx = 0;
- int desty = 0;
- int pixel = 0;
-
- if (self == 0)
- {
- return 1;
- }
- if (dest == 0)
- {
- return 1;
- }
- if (self->type != WND_TYPE_BITMAP && self->type != WND_TYPE_IMAGE)
- {
- return 1;
- }
- if (dest->type != WND_TYPE_BITMAP && dest->type != WND_TYPE_IMAGE)
- {
- return 1;
- }
- if (self->bpp != dest->bpp)
- {
- return 1;
- }
- destx = 0;
- desty = 0;
- if (!check_bounds(self, &x, &y, &cx, &cy))
- {
- return 1;
- }
- if (!check_bounds(dest, &destx, &desty, &cx, &cy))
- {
- return 1;
- }
- if (self->bpp == 24)
- {
- for (i = 0; i < cy; i++)
- {
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL32(self->data, j + x, i + y, self->width);
- SETPIXEL32(dest->data, j + destx, i + desty, dest->width, pixel);
- }
- }
- }
- else if (self->bpp == 15 || self->bpp == 16)
- {
- for (i = 0; i < cy; i++)
- {
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL16(self->data, j + x, i + y, self->width);
- SETPIXEL16(dest->data, j + destx, i + desty, dest->width, pixel);
- }
- }
- }
- else if (self->bpp == 8)
- {
- for (i = 0; i < cy; i++)
- {
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL8(self->data, j + x, i + y, self->width);
- SETPIXEL8(dest->data, j + destx, i + desty, dest->width, pixel);
- }
- }
- }
- else
- {
- return 1;
- }
- return 0;
+ int i = 0;
+ int j = 0;
+ int destx = 0;
+ int desty = 0;
+ int pixel = 0;
+
+ if (self == 0)
+ {
+ return 1;
+ }
+
+ if (dest == 0)
+ {
+ return 1;
+ }
+
+ if (self->type != WND_TYPE_BITMAP && self->type != WND_TYPE_IMAGE)
+ {
+ return 1;
+ }
+
+ if (dest->type != WND_TYPE_BITMAP && dest->type != WND_TYPE_IMAGE)
+ {
+ return 1;
+ }
+
+ if (self->bpp != dest->bpp)
+ {
+ return 1;
+ }
+
+ destx = 0;
+ desty = 0;
+
+ if (!check_bounds(self, &x, &y, &cx, &cy))
+ {
+ return 1;
+ }
+
+ if (!check_bounds(dest, &destx, &desty, &cx, &cy))
+ {
+ return 1;
+ }
+
+ if (self->bpp == 24)
+ {
+ for (i = 0; i < cy; i++)
+ {
+ for (j = 0; j < cx; j++)
+ {
+ pixel = GETPIXEL32(self->data, j + x, i + y, self->width);
+ SETPIXEL32(dest->data, j + destx, i + desty, dest->width, pixel);
+ }
+ }
+ }
+ else if (self->bpp == 15 || self->bpp == 16)
+ {
+ for (i = 0; i < cy; i++)
+ {
+ for (j = 0; j < cx; j++)
+ {
+ pixel = GETPIXEL16(self->data, j + x, i + y, self->width);
+ SETPIXEL16(dest->data, j + destx, i + desty, dest->width, pixel);
+ }
+ }
+ }
+ else if (self->bpp == 8)
+ {
+ for (i = 0; i < cy; i++)
+ {
+ for (j = 0; j < cx; j++)
+ {
+ pixel = GETPIXEL8(self->data, j + x, i + y, self->width);
+ SETPIXEL8(dest->data, j + destx, i + desty, dest->width, pixel);
+ }
+ }
+ }
+ else
+ {
+ return 1;
+ }
+
+ return 0;
}
/*****************************************************************************/
/* copy part of self at x, y to 0, 0 in dest */
/* returns error */
int APP_CC
-xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap* self,
- struct xrdp_bitmap* dest,
+xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
+ struct xrdp_bitmap *dest,
int x, int y, int cx, int cy)
{
- int i = 0;
- int j = 0;
- int destx = 0;
- int desty = 0;
- int pixel = 0;
- int crc = 0;
- int incs = 0;
- int incd = 0;
- unsigned char* s8 = (unsigned char *)NULL;
- unsigned char* d8 = (unsigned char *)NULL;
- unsigned short* s16 = (unsigned short *)NULL;
- unsigned short* d16 = (unsigned short *)NULL;
-
- if (self == 0)
- {
- return 1;
- }
- if (dest == 0)
- {
- return 1;
- }
- if (self->type != WND_TYPE_BITMAP && self->type != WND_TYPE_IMAGE)
- {
- return 1;
- }
- if (dest->type != WND_TYPE_BITMAP && dest->type != WND_TYPE_IMAGE)
- {
- return 1;
- }
- if (self->bpp != dest->bpp)
- {
- return 1;
- }
- destx = 0;
- desty = 0;
- if (!check_bounds(self, &x, &y, &cx, &cy))
- {
- return 1;
- }
- if (!check_bounds(dest, &destx, &desty, &cx, &cy))
- {
- return 1;
- }
- CRC_START(crc);
- if (self->bpp == 24)
- {
- for (i = 0; i < cy; i++)
- {
- for (j = 0; j < cx; j++)
- {
- pixel = GETPIXEL32(self->data, j + x, i + y, self->width);
- CRC_PASS(pixel, crc);
- CRC_PASS(pixel >> 8, crc);
- CRC_PASS(pixel >> 16, crc);
- SETPIXEL32(dest->data, j + destx, i + desty, dest->width, pixel);
- }
- }
- }
- else if (self->bpp == 15 || self->bpp == 16)
- {
- s16 = ((unsigned short*)(self->data)) + (self->width * y + x);
- d16 = ((unsigned short*)(dest->data)) + (dest->width * desty + destx);
- incs = self->width - cx;
- incd = dest->width - cx;
- for (i = 0; i < cy; i++)
- {
- for (j = 0; j < cx; j++)
- {
- pixel = *s16;
- CRC_PASS(pixel, crc);
- CRC_PASS(pixel >> 8, crc);
- *d16 = pixel;
- s16++;
- d16++;
- }
- s16 += incs;
- d16 += incd;
- }
- }
- else if (self->bpp == 8)
- {
- s8 = ((unsigned char*)(self->data)) + (self->width * y + x);
- d8 = ((unsigned char*)(dest->data)) + (dest->width * desty + destx);
- incs = self->width - cx;
- incd = dest->width - cx;
- for (i = 0; i < cy; i++)
- {
- for (j = 0; j < cx; j++)
- {
- pixel = *s8;
- CRC_PASS(pixel, crc);
- *d8 = pixel;
- s8++;
- d8++;
- }
- s8 += incs;
- d8 += incd;
- }
- }
- else
- {
- return 1;
- }
- CRC_END(crc);
- dest->crc = crc;
- return 0;
+ int i = 0;
+ int j = 0;
+ int destx = 0;
+ int desty = 0;
+ int pixel = 0;
+ int crc = 0;
+ int incs = 0;
+ int incd = 0;
+ unsigned char *s8 = (unsigned char *)NULL;
+ unsigned char *d8 = (unsigned char *)NULL;
+ unsigned short *s16 = (unsigned short *)NULL;
+ unsigned short *d16 = (unsigned short *)NULL;
+
+ if (self == 0)
+ {
+ return 1;
+ }
+
+ if (dest == 0)
+ {
+ return 1;
+ }
+
+ if (self->type != WND_TYPE_BITMAP && self->type != WND_TYPE_IMAGE)
+ {
+ return 1;
+ }
+
+ if (dest->type != WND_TYPE_BITMAP && dest->type != WND_TYPE_IMAGE)
+ {
+ return 1;
+ }
+
+ if (self->bpp != dest->bpp)
+ {
+ return 1;
+ }
+
+ destx = 0;
+ desty = 0;
+
+ if (!check_bounds(self, &x, &y, &cx, &cy))
+ {
+ return 1;
+ }
+
+ if (!check_bounds(dest, &destx, &desty, &cx, &cy))
+ {
+ return 1;
+ }
+
+ CRC_START(crc);
+
+ if (self->bpp == 24)
+ {
+ for (i = 0; i < cy; i++)
+ {
+ for (j = 0; j < cx; j++)
+ {
+ pixel = GETPIXEL32(self->data, j + x, i + y, self->width);
+ CRC_PASS(pixel, crc);
+ CRC_PASS(pixel >> 8, crc);
+ CRC_PASS(pixel >> 16, crc);
+ SETPIXEL32(dest->data, j + destx, i + desty, dest->width, pixel);
+ }
+ }
+ }
+ else if (self->bpp == 15 || self->bpp == 16)
+ {
+ s16 = ((unsigned short *)(self->data)) + (self->width * y + x);
+ d16 = ((unsigned short *)(dest->data)) + (dest->width * desty + destx);
+ incs = self->width - cx;
+ incd = dest->width - cx;
+
+ for (i = 0; i < cy; i++)
+ {
+ for (j = 0; j < cx; j++)
+ {
+ pixel = *s16;
+ CRC_PASS(pixel, crc);
+ CRC_PASS(pixel >> 8, crc);
+ *d16 = pixel;
+ s16++;
+ d16++;
+ }
+
+ s16 += incs;
+ d16 += incd;
+ }
+ }
+ else if (self->bpp == 8)
+ {
+ s8 = ((unsigned char *)(self->data)) + (self->width * y + x);
+ d8 = ((unsigned char *)(dest->data)) + (dest->width * desty + destx);
+ incs = self->width - cx;
+ incd = dest->width - cx;
+
+ for (i = 0; i < cy; i++)
+ {
+ for (j = 0; j < cx; j++)
+ {
+ pixel = *s8;
+ CRC_PASS(pixel, crc);
+ *d8 = pixel;
+ s8++;
+ d8++;
+ }
+
+ s8 += incs;
+ d8 += incd;
+ }
+ }
+ else
+ {
+ return 1;
+ }
+
+ CRC_END(crc);
+ dest->crc = crc;
+ return 0;
}
/*****************************************************************************/
/* returns true if they are the same, else returns false */
int APP_CC
-xrdp_bitmap_compare(struct xrdp_bitmap* self,
- struct xrdp_bitmap* b)
+xrdp_bitmap_compare(struct xrdp_bitmap *self,
+ struct xrdp_bitmap *b)
{
- if (self == 0)
- {
- return 0;
- }
- if (b == 0)
- {
- return 0;
- }
- if (self->bpp != b->bpp)
- {
- return 0;
- }
- if (self->width != b->width)
- {
- return 0;
- }
- if (self->height != b->height)
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (b == 0)
+ {
+ return 0;
+ }
+
+ if (self->bpp != b->bpp)
+ {
+ return 0;
+ }
+
+ if (self->width != b->width)
+ {
+ return 0;
+ }
+
+ if (self->height != b->height)
+ {
+ return 0;
+ }
+
+ if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
+ {
+ return 1;
+ }
+
return 0;
- }
- if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
- {
- return 1;
- }
- return 0;
}
/*****************************************************************************/
/* returns true if they are the same, else returns false */
int APP_CC
-xrdp_bitmap_compare_with_crc(struct xrdp_bitmap* self,
- struct xrdp_bitmap* b)
+xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
+ struct xrdp_bitmap *b)
{
- if (self == 0)
- {
- return 0;
- }
- if (b == 0)
- {
- return 0;
- }
- if (self->bpp != b->bpp)
- {
- return 0;
- }
- if (self->width != b->width)
- {
- return 0;
- }
- if (self->height != b->height)
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (b == 0)
+ {
+ return 0;
+ }
+
+ if (self->bpp != b->bpp)
+ {
+ return 0;
+ }
+
+ if (self->width != b->width)
+ {
+ return 0;
+ }
+
+ if (self->height != b->height)
+ {
+ return 0;
+ }
+
+ if (self->crc == b->crc)
+ {
+ return 1;
+ }
+
return 0;
- }
- if (self->crc == b->crc)
- {
- return 1;
- }
- return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_bitmap_draw_focus_box(struct xrdp_bitmap* self,
- struct xrdp_painter* painter,
+xrdp_bitmap_draw_focus_box(struct xrdp_bitmap *self,
+ struct xrdp_painter *painter,
int x, int y, int cx, int cy)
{
- painter->rop = 0xf0;
- xrdp_painter_begin_update(painter);
- painter->use_clip = 0;
- painter->mix_mode = 1;
- painter->brush.pattern[0] = 0xaa;
- painter->brush.pattern[1] = 0x55;
- painter->brush.pattern[2] = 0xaa;
- painter->brush.pattern[3] = 0x55;
- painter->brush.pattern[4] = 0xaa;
- painter->brush.pattern[5] = 0x55;
- painter->brush.pattern[6] = 0xaa;
- painter->brush.pattern[7] = 0x55;
- painter->brush.x_orgin = x;
- painter->brush.x_orgin = x;
- painter->brush.style = 3;
- painter->fg_color = self->wm->black;
- painter->bg_color = self->parent->bg_color;
- /* top */
- xrdp_painter_fill_rect(painter, self, x, y, cx, 1);
- /* bottom */
- xrdp_painter_fill_rect(painter, self, x, y + (cy - 1), cx, 1);
- /* left */
- xrdp_painter_fill_rect(painter, self, x, y + 1, 1, cy - 2);
- /* right */
- xrdp_painter_fill_rect(painter, self, x + (cx - 1), y + 1, 1, cy - 2);
- xrdp_painter_end_update(painter);
- painter->rop = 0xcc;
- painter->mix_mode = 0;
- return 0;
+ painter->rop = 0xf0;
+ xrdp_painter_begin_update(painter);
+ painter->use_clip = 0;
+ painter->mix_mode = 1;
+ painter->brush.pattern[0] = 0xaa;
+ painter->brush.pattern[1] = 0x55;
+ painter->brush.pattern[2] = 0xaa;
+ painter->brush.pattern[3] = 0x55;
+ painter->brush.pattern[4] = 0xaa;
+ painter->brush.pattern[5] = 0x55;
+ painter->brush.pattern[6] = 0xaa;
+ painter->brush.pattern[7] = 0x55;
+ painter->brush.x_orgin = x;
+ painter->brush.x_orgin = x;
+ painter->brush.style = 3;
+ painter->fg_color = self->wm->black;
+ painter->bg_color = self->parent->bg_color;
+ /* top */
+ xrdp_painter_fill_rect(painter, self, x, y, cx, 1);
+ /* bottom */
+ xrdp_painter_fill_rect(painter, self, x, y + (cy - 1), cx, 1);
+ /* left */
+ xrdp_painter_fill_rect(painter, self, x, y + 1, 1, cy - 2);
+ /* right */
+ xrdp_painter_fill_rect(painter, self, x + (cx - 1), y + 1, 1, cy - 2);
+ xrdp_painter_end_update(painter);
+ painter->rop = 0xcc;
+ painter->mix_mode = 0;
+ return 0;
}
/*****************************************************************************/
/* x and y are in relation to self for 0, 0 is the top left of the control */
static int APP_CC
-xrdp_bitmap_draw_button(struct xrdp_bitmap* self,
- struct xrdp_painter* painter,
+xrdp_bitmap_draw_button(struct xrdp_bitmap *self,
+ struct xrdp_painter *painter,
int x, int y, int w, int h,
int down)
{
- if (down)
- {
- /* gray box */
- painter->fg_color = self->wm->grey;
- xrdp_painter_fill_rect(painter, self, x, y, w, h);
- /* black top line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, x, y, w, 1);
- /* black left line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, x, y, 1, h);
- /* dark grey top line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, x + 1, y + 1, w - 2, 1);
- /* dark grey left line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, x + 1, y + 1, 1, h - 2);
- /* dark grey bottom line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, x + 1, y + (h - 2), w - 1, 1);
- /* dark grey right line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, x + (w - 2), y + 1, 1, h - 1);
- /* black bottom line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, x, y + (h - 1), w, 1);
- /* black right line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, x + (w - 1), y, 1, h);
- }
- else
- {
- /* gray box */
- painter->fg_color = self->wm->grey;
- xrdp_painter_fill_rect(painter, self, x, y, w, h);
- /* white top line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, x, y, w, 1);
- /* white left line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, x, y, 1, h);
- /* dark grey bottom line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, x + 1, y + (h - 2), w - 1, 1);
- /* dark grey right line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, (x + w) - 2, y + 1, 1, h - 1);
- /* black bottom line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, x, y + (h - 1), w, 1);
- /* black right line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, x + (w - 1), y, 1, h);
- }
- return 0;
+ if (down)
+ {
+ /* gray box */
+ painter->fg_color = self->wm->grey;
+ xrdp_painter_fill_rect(painter, self, x, y, w, h);
+ /* black top line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, x, y, w, 1);
+ /* black left line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, x, y, 1, h);
+ /* dark grey top line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, x + 1, y + 1, w - 2, 1);
+ /* dark grey left line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, x + 1, y + 1, 1, h - 2);
+ /* dark grey bottom line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, x + 1, y + (h - 2), w - 1, 1);
+ /* dark grey right line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, x + (w - 2), y + 1, 1, h - 1);
+ /* black bottom line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, x, y + (h - 1), w, 1);
+ /* black right line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, x + (w - 1), y, 1, h);
+ }
+ else
+ {
+ /* gray box */
+ painter->fg_color = self->wm->grey;
+ xrdp_painter_fill_rect(painter, self, x, y, w, h);
+ /* white top line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, x, y, w, 1);
+ /* white left line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, x, y, 1, h);
+ /* dark grey bottom line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, x + 1, y + (h - 2), w - 1, 1);
+ /* dark grey right line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, (x + w) - 2, y + 1, 1, h - 1);
+ /* black bottom line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, x, y + (h - 1), w, 1);
+ /* black right line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, x + (w - 1), y, 1, h);
+ }
+
+ return 0;
}
/*****************************************************************************/
/* nil for rect means the whole thing */
/* returns error */
int APP_CC
-xrdp_bitmap_invalidate(struct xrdp_bitmap* self, struct xrdp_rect* rect)
+xrdp_bitmap_invalidate(struct xrdp_bitmap *self, struct xrdp_rect *rect)
{
- int i;
- int w;
- int h;
- int x;
- int y;
- struct xrdp_bitmap* b;
- struct xrdp_rect r1;
- struct xrdp_rect r2;
- struct xrdp_painter* painter;
- twchar wtext[256];
- char text[256];
- char* p;
-
- if (self == 0) /* if no bitmap */
- {
- return 0;
- }
- if (self->type == WND_TYPE_BITMAP) /* if 0, bitmap, leave */
- {
- return 0;
- }
- painter = xrdp_painter_create(self->wm, self->wm->session);
- xrdp_painter_font_needed(painter);
- painter->rop = 0xcc; /* copy */
- if (rect == 0)
- {
- painter->use_clip = 0;
- }
- else
- {
- if (ISRECTEMPTY(*rect))
- {
- xrdp_painter_delete(painter);
- return 0;
- }
- painter->clip = *rect;
- painter->use_clip = &painter->clip;
- }
- xrdp_painter_begin_update(painter);
- if (self->type == WND_TYPE_WND) /* 1 */
- {
- /* draw grey background */
- painter->fg_color = self->bg_color;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
- /* top white line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 2, 1);
- /* left white line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 2);
- /* bottom dark grey line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 1, self->height - 2,
- self->width - 2, 1);
- /* right dark grey line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, self->width - 2, 1, 1,
- self->height - 2);
- /* bottom black line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, 0, self->height - 1,
- self->width, 1);
- /* right black line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, self->width - 1, 0,
- 1, self->height);
- if (self->wm->focused_window == self)
+ int i;
+ int w;
+ int h;
+ int x;
+ int y;
+ struct xrdp_bitmap *b;
+ struct xrdp_rect r1;
+ struct xrdp_rect r2;
+ struct xrdp_painter *painter;
+ twchar wtext[256];
+ char text[256];
+ char *p;
+
+ if (self == 0) /* if no bitmap */
{
- /* active title bar */
- painter->fg_color = self->wm->blue;
- xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
- painter->fg_color = self->wm->white;
+ return 0;
}
- else
+
+ if (self->type == WND_TYPE_BITMAP) /* if 0, bitmap, leave */
{
- /* inactive title bar */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
- painter->fg_color = self->wm->black;
+ return 0;
}
- xrdp_painter_draw_text(painter, self, 4, 4, self->caption1);
- }
- else if (self->type == WND_TYPE_SCREEN) /* 2 */
- {
- if (self->wm->mm->mod != 0)
- {
- if (self->wm->mm->mod->mod_event != 0)
- {
- if (rect != 0)
- {
- x = rect->left;
- y = rect->top;
- w = rect->right - rect->left;
- h = rect->bottom - rect->top;
- if (check_bounds(self->wm->screen, &x, &y, &w, &h))
- {
- self->wm->mm->mod->mod_event(self->wm->mm->mod, WM_INVALIDATE,
- MAKELONG(y, x), MAKELONG(h, w),
- 0, 0);
- }
- }
- else
- {
- x = 0;
- y = 0;
- w = self->wm->screen->width;
- h = self->wm->screen->height;
- self->wm->mm->mod->mod_event(self->wm->mm->mod, WM_INVALIDATE,
- MAKELONG(y, x), MAKELONG(h, w),
- 0, 0);
- }
- }
+
+ painter = xrdp_painter_create(self->wm, self->wm->session);
+ xrdp_painter_font_needed(painter);
+ painter->rop = 0xcc; /* copy */
+
+ if (rect == 0)
+ {
+ painter->use_clip = 0;
}
else
{
- painter->fg_color = self->bg_color;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
- }
- }
- else if (self->type == WND_TYPE_BUTTON) /* 3 */
- {
- if (self->state == BUTTON_STATE_UP) /* 0 */
- {
- xrdp_bitmap_draw_button(self, painter, 0, 0,
- self->width, self->height, 0);
- w = xrdp_painter_text_width(painter, self->caption1);
- h = xrdp_painter_text_height(painter, self->caption1);
- painter->fg_color = self->wm->black;
- xrdp_painter_draw_text(painter, self, self->width / 2 - w / 2,
- self->height / 2 - h / 2, self->caption1);
- if (self->parent != 0)
- {
- if (self->wm->focused_window == self->parent)
+ if (ISRECTEMPTY(*rect))
{
- if (self->parent->focused_control == self)
- {
- xrdp_bitmap_draw_focus_box(self, painter, 4, 4, self->width - 8,
- self->height - 8);
- }
+ xrdp_painter_delete(painter);
+ return 0;
}
- }
- }
- else if (self->state == BUTTON_STATE_DOWN) /* 1 */
- {
- xrdp_bitmap_draw_button(self, painter, 0, 0,
- self->width, self->height, 1);
- w = xrdp_painter_text_width(painter, self->caption1);
- h = xrdp_painter_text_height(painter, self->caption1);
- painter->fg_color = self->wm->black;
- xrdp_painter_draw_text(painter, self, (self->width / 2 - w / 2) + 1,
- (self->height / 2 - h / 2) + 1, self->caption1);
- if (self->parent != 0)
- if (self->wm->focused_window == self->parent)
- if (self->parent->focused_control == self)
- xrdp_bitmap_draw_focus_box(self, painter, 4, 4, self->width - 8,
- self->height - 8);
- }
- }
- else if (self->type == WND_TYPE_IMAGE) /* 4 */
- {
- xrdp_painter_copy(painter, self, self, 0, 0, self->width,
- self->height, 0, 0);
- }
- else if (self->type == WND_TYPE_EDIT) /* 5 */
- {
- /* draw gray box */
- painter->fg_color = self->wm->grey;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
- /* main white background */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3,
- self->height - 3);
- /* dark grey top line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, 1);
- /* dark grey left line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 0, 0, 1, self->height);
- /* white bottom line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 0, self->height- 1, self->width, 1);
- /* white right line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, self->width - 1, 0, 1, self->height);
- /* black left line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 3);
- /* black top line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3, 1);
- /* draw text */
- painter->fg_color = self->wm->black;
- if (self->password_char != 0)
- {
- i = g_mbstowcs(0, self->caption1, 0);
- g_memset(text, self->password_char, i);
- text[i] = 0;
- xrdp_painter_draw_text(painter, self, 4, 2, text);
- }
- else
- {
- xrdp_painter_draw_text(painter, self, 4, 2, self->caption1);
+
+ painter->clip = *rect;
+ painter->use_clip = &painter->clip;
}
- /* draw xor box(cursor) */
- if (self->parent != 0)
+
+ xrdp_painter_begin_update(painter);
+
+ if (self->type == WND_TYPE_WND) /* 1 */
{
- if (self->parent->focused_control == self)
- {
- if (self->password_char != 0)
+ /* draw grey background */
+ painter->fg_color = self->bg_color;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
+ /* top white line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 2, 1);
+ /* left white line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 2);
+ /* bottom dark grey line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 1, self->height - 2,
+ self->width - 2, 1);
+ /* right dark grey line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, self->width - 2, 1, 1,
+ self->height - 2);
+ /* bottom black line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, 0, self->height - 1,
+ self->width, 1);
+ /* right black line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, self->width - 1, 0,
+ 1, self->height);
+
+ if (self->wm->focused_window == self)
{
- wchar_repeat(wtext, 255, self->password_char, self->edit_pos);
- wtext[self->edit_pos] = 0;
- g_wcstombs(text, wtext, 255);
+ /* active title bar */
+ painter->fg_color = self->wm->blue;
+ xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
+ painter->fg_color = self->wm->white;
}
else
{
- g_mbstowcs(wtext, self->caption1, 255);
- wtext[self->edit_pos] = 0;
- g_wcstombs(text, wtext, 255);
+ /* inactive title bar */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 3, 3, self->width - 5, 18);
+ painter->fg_color = self->wm->black;
}
- w = xrdp_painter_text_width(painter, text);
- painter->fg_color = self->wm->white;
- painter->rop = 0x5a;
- xrdp_painter_fill_rect(painter, self, 4 + w, 3, 2, self->height - 6);
- }
+
+ xrdp_painter_draw_text(painter, self, 4, 4, self->caption1);
}
- /* reset rop back */
- painter->rop = 0xcc;
- }
- else if (self->type == WND_TYPE_LABEL) /* 6 */
- {
- painter->fg_color = self->wm->black;
- xrdp_painter_draw_text(painter, self, 0, 0, self->caption1);
- }
- else if (self->type == WND_TYPE_COMBO) /* 7 combo box */
- {
- /* draw gray box */
- painter->fg_color = self->wm->grey;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
- /* white background */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3,
- self->height - 3);
- if (self->parent->focused_control == self)
- {
- painter->fg_color = self->wm->dark_blue;
- xrdp_painter_fill_rect(painter, self, 3, 3, (self->width - 6) - 18,
- self->height - 5);
- }
- /* dark grey top line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, 1);
- /* dark grey left line */
- painter->fg_color = self->wm->dark_grey;
- xrdp_painter_fill_rect(painter, self, 0, 0, 1, self->height);
- /* white bottom line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 0, self->height- 1, self->width, 1);
- /* white right line */
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, self->width - 1, 0, 1, self->height);
- /* black left line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 3);
- /* black top line */
- painter->fg_color = self->wm->black;
- xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3, 1);
- /* draw text */
- if (self->parent->focused_control == self)
+ else if (self->type == WND_TYPE_SCREEN) /* 2 */
{
- painter->fg_color = self->wm->white;
+ if (self->wm->mm->mod != 0)
+ {
+ if (self->wm->mm->mod->mod_event != 0)
+ {
+ if (rect != 0)
+ {
+ x = rect->left;
+ y = rect->top;
+ w = rect->right - rect->left;
+ h = rect->bottom - rect->top;
+
+ if (check_bounds(self->wm->screen, &x, &y, &w, &h))
+ {
+ self->wm->mm->mod->mod_event(self->wm->mm->mod, WM_INVALIDATE,
+ MAKELONG(y, x), MAKELONG(h, w),
+ 0, 0);
+ }
+ }
+ else
+ {
+ x = 0;
+ y = 0;
+ w = self->wm->screen->width;
+ h = self->wm->screen->height;
+ self->wm->mm->mod->mod_event(self->wm->mm->mod, WM_INVALIDATE,
+ MAKELONG(y, x), MAKELONG(h, w),
+ 0, 0);
+ }
+ }
+ }
+ else
+ {
+ painter->fg_color = self->bg_color;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
+ }
}
- else
+ else if (self->type == WND_TYPE_BUTTON) /* 3 */
{
- painter->fg_color = self->wm->black;
+ if (self->state == BUTTON_STATE_UP) /* 0 */
+ {
+ xrdp_bitmap_draw_button(self, painter, 0, 0,
+ self->width, self->height, 0);
+ w = xrdp_painter_text_width(painter, self->caption1);
+ h = xrdp_painter_text_height(painter, self->caption1);
+ painter->fg_color = self->wm->black;
+ xrdp_painter_draw_text(painter, self, self->width / 2 - w / 2,
+ self->height / 2 - h / 2, self->caption1);
+
+ if (self->parent != 0)
+ {
+ if (self->wm->focused_window == self->parent)
+ {
+ if (self->parent->focused_control == self)
+ {
+ xrdp_bitmap_draw_focus_box(self, painter, 4, 4, self->width - 8,
+ self->height - 8);
+ }
+ }
+ }
+ }
+ else if (self->state == BUTTON_STATE_DOWN) /* 1 */
+ {
+ xrdp_bitmap_draw_button(self, painter, 0, 0,
+ self->width, self->height, 1);
+ w = xrdp_painter_text_width(painter, self->caption1);
+ h = xrdp_painter_text_height(painter, self->caption1);
+ painter->fg_color = self->wm->black;
+ xrdp_painter_draw_text(painter, self, (self->width / 2 - w / 2) + 1,
+ (self->height / 2 - h / 2) + 1, self->caption1);
+
+ if (self->parent != 0)
+ if (self->wm->focused_window == self->parent)
+ if (self->parent->focused_control == self)
+ xrdp_bitmap_draw_focus_box(self, painter, 4, 4, self->width - 8,
+ self->height - 8);
+ }
}
- xrdp_painter_draw_text(painter, self, 4, 2,
- (char*)list_get_item(self->string_list, self->item_index));
- /* draw button on right */
- x = self->width - 20;
- y = 2;
- w = (self->width - x) - 2;
- h = self->height - 4;
- /* looks better with a background around */
- painter->fg_color = self->wm->grey;
- xrdp_painter_fill_rect(painter, self, x, y, w, h);
- if (self->state == BUTTON_STATE_UP) /* 0 */
+ else if (self->type == WND_TYPE_IMAGE) /* 4 */
{
- xrdp_bitmap_draw_button(self, painter, x+1, y+1, w-1, h-1, 0);
+ xrdp_painter_copy(painter, self, self, 0, 0, self->width,
+ self->height, 0, 0);
}
- else
+ else if (self->type == WND_TYPE_EDIT) /* 5 */
{
- xrdp_bitmap_draw_button(self, painter, x+1, y+1, w-1, h-1, 1);
- }
- /* draw the arrow */
- w = w / 2;
- x = x + (w / 2) + 1;
- h = (h / 2) + 2;
- y = y + (h / 2) + 1;
- painter->fg_color = self->wm->black;
- for (i=w; i>0; i=i-2)
- {
- xrdp_painter_fill_rect(painter, self, x, y, i, 1);
- y++;
- x = x + 1;
- }
- }
- else if (self->type == WND_TYPE_SPECIAL) /* 8 special */
- {
- if (self->popped_from != 0)
- {
- /* change height if there are too many items in the list */
- i = xrdp_painter_text_height(painter, "W");
- i = self->popped_from->string_list->count * i;
- if (i > self->height)
- {
- self->height = i;
- }
- }
- painter->fg_color = self->wm->white;
- xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
- /* draw the list items */
- if (self->popped_from != 0)
- {
- y = 0;
- for (i = 0; i < self->popped_from->string_list->count; i++)
- {
- p = (char*)list_get_item(self->popped_from->string_list, i);
- h = xrdp_painter_text_height(painter, p);
- self->item_height = h;
- if (i == self->item_index)
+ /* draw gray box */
+ painter->fg_color = self->wm->grey;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
+ /* main white background */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3,
+ self->height - 3);
+ /* dark grey top line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, 1);
+ /* dark grey left line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 0, 0, 1, self->height);
+ /* white bottom line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 0, self->height - 1, self->width, 1);
+ /* white right line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, self->width - 1, 0, 1, self->height);
+ /* black left line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 3);
+ /* black top line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3, 1);
+ /* draw text */
+ painter->fg_color = self->wm->black;
+
+ if (self->password_char != 0)
{
- painter->fg_color = self->wm->blue;
- xrdp_painter_fill_rect(painter, self, 0, y, self->width, h);
- painter->fg_color = self->wm->white;
+ i = g_mbstowcs(0, self->caption1, 0);
+ g_memset(text, self->password_char, i);
+ text[i] = 0;
+ xrdp_painter_draw_text(painter, self, 4, 2, text);
}
else
{
- painter->fg_color = self->wm->black;
+ xrdp_painter_draw_text(painter, self, 4, 2, self->caption1);
}
- xrdp_painter_draw_text(painter, self, 2, y, p);
- y = y + h;
- }
- }
- }
- /* notify */
- if (self->notify != 0)
- {
- self->notify(self, self, WM_PAINT, (long)painter, 0); /* 3 */
- }
- /* draw any child windows in the area */
- for (i = 0; i < self->child_list->count; i++)
- {
- b = (struct xrdp_bitmap*)list_get_item(self->child_list, i);
- if (rect == 0)
+
+ /* draw xor box(cursor) */
+ if (self->parent != 0)
+ {
+ if (self->parent->focused_control == self)
+ {
+ if (self->password_char != 0)
+ {
+ wchar_repeat(wtext, 255, self->password_char, self->edit_pos);
+ wtext[self->edit_pos] = 0;
+ g_wcstombs(text, wtext, 255);
+ }
+ else
+ {
+ g_mbstowcs(wtext, self->caption1, 255);
+ wtext[self->edit_pos] = 0;
+ g_wcstombs(text, wtext, 255);
+ }
+
+ w = xrdp_painter_text_width(painter, text);
+ painter->fg_color = self->wm->white;
+ painter->rop = 0x5a;
+ xrdp_painter_fill_rect(painter, self, 4 + w, 3, 2, self->height - 6);
+ }
+ }
+
+ /* reset rop back */
+ painter->rop = 0xcc;
+ }
+ else if (self->type == WND_TYPE_LABEL) /* 6 */
{
- xrdp_bitmap_invalidate(b, 0);
+ painter->fg_color = self->wm->black;
+ xrdp_painter_draw_text(painter, self, 0, 0, self->caption1);
}
- else
+ else if (self->type == WND_TYPE_COMBO) /* 7 combo box */
{
- MAKERECT(r1, b->left, b->top, b->width, b->height);
- if (rect_intersect(rect, &r1, &r2))
- {
- RECTOFFSET(r2, -(b->left), -(b->top));
- xrdp_bitmap_invalidate(b, &r2);
- }
- }
- }
- xrdp_painter_end_update(painter);
- xrdp_painter_delete(painter);
- return 0;
-}
+ /* draw gray box */
+ painter->fg_color = self->wm->grey;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
+ /* white background */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3,
+ self->height - 3);
-/*****************************************************************************/
-/* returns error */
-int APP_CC
-xrdp_bitmap_def_proc(struct xrdp_bitmap* self, int msg,
- int param1, int param2)
-{
- twchar c;
- int n;
- int i;
- int shift;
- int ext;
- int scan_code;
- int num_bytes;
- int num_chars;
- struct xrdp_bitmap* b;
- struct xrdp_bitmap* focus_out_control;
-
- if (self == 0)
- {
- return 0;
- }
- if (self->wm == 0)
- {
- return 0;
- }
- if (self->type == WND_TYPE_WND)
- {
- if (msg == WM_KEYDOWN)
- {
- scan_code = param1 % 128;
- if (scan_code == 15) /* tab */
- {
- /* move to next tab stop */
- shift = self->wm->keys[42] || self->wm->keys[54];
- i = -1;
- if (self->child_list != 0)
+ if (self->parent->focused_control == self)
{
- i = list_index_of(self->child_list, (long)self->focused_control);
+ painter->fg_color = self->wm->dark_blue;
+ xrdp_painter_fill_rect(painter, self, 3, 3, (self->width - 6) - 18,
+ self->height - 5);
}
- if (shift)
+
+ /* dark grey top line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, 1);
+ /* dark grey left line */
+ painter->fg_color = self->wm->dark_grey;
+ xrdp_painter_fill_rect(painter, self, 0, 0, 1, self->height);
+ /* white bottom line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 0, self->height - 1, self->width, 1);
+ /* white right line */
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, self->width - 1, 0, 1, self->height);
+ /* black left line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, 1, 1, 1, self->height - 3);
+ /* black top line */
+ painter->fg_color = self->wm->black;
+ xrdp_painter_fill_rect(painter, self, 1, 1, self->width - 3, 1);
+
+ /* draw text */
+ if (self->parent->focused_control == self)
{
- i--;
- if (i < 0)
- {
- i = self->child_list->count - 1;
- }
+ painter->fg_color = self->wm->white;
}
else
{
- i++;
- if (i >= self->child_list->count)
- {
- i = 0;
- }
+ painter->fg_color = self->wm->black;
}
- n = self->child_list->count;
- b = (struct xrdp_bitmap*)list_get_item(self->child_list, i);
- while (b != self->focused_control && b != 0 && n > 0)
+
+ xrdp_painter_draw_text(painter, self, 4, 2,
+ (char *)list_get_item(self->string_list, self->item_index));
+ /* draw button on right */
+ x = self->width - 20;
+ y = 2;
+ w = (self->width - x) - 2;
+ h = self->height - 4;
+ /* looks better with a background around */
+ painter->fg_color = self->wm->grey;
+ xrdp_painter_fill_rect(painter, self, x, y, w, h);
+
+ if (self->state == BUTTON_STATE_UP) /* 0 */
{
- n--;
- if (b->tab_stop)
- {
- focus_out_control = self->focused_control;
- self->focused_control = b;
- xrdp_bitmap_invalidate(focus_out_control, 0);
- xrdp_bitmap_invalidate(b, 0);
- break;
- }
- if (shift)
- {
- i--;
- if (i < 0)
- {
- i = self->child_list->count - 1;
- }
- }
- else
- {
- i++;
- if (i >= self->child_list->count)
- {
- i = 0;
- }
- }
- b = (struct xrdp_bitmap*)list_get_item(self->child_list, i);
+ xrdp_bitmap_draw_button(self, painter, x + 1, y + 1, w - 1, h - 1, 0);
}
- }
- else if (scan_code == 28) /* enter */
- {
- if (self->default_button != 0)
+ else
{
- if (self->notify != 0)
- {
- /* I think this should use def_proc */
- self->notify(self, self->default_button, 1, 0, 0);
- return 0;
- }
+ xrdp_bitmap_draw_button(self, painter, x + 1, y + 1, w - 1, h - 1, 1);
}
- }
- else if (scan_code == 1) /* esc */
- {
- if (self->esc_button != 0)
+
+ /* draw the arrow */
+ w = w / 2;
+ x = x + (w / 2) + 1;
+ h = (h / 2) + 2;
+ y = y + (h / 2) + 1;
+ painter->fg_color = self->wm->black;
+
+ for (i = w; i > 0; i = i - 2)
{
- if (self->notify != 0)
- {
- /* I think this should use def_proc */
- self->notify(self, self->esc_button, 1, 0, 0);
- return 0;
- }
+ xrdp_painter_fill_rect(painter, self, x, y, i, 1);
+ y++;
+ x = x + 1;
}
- }
}
- if (self->focused_control != 0)
+ else if (self->type == WND_TYPE_SPECIAL) /* 8 special */
{
- xrdp_bitmap_def_proc(self->focused_control, msg, param1, param2);
- }
- }
- else if (self->type == WND_TYPE_EDIT)
- {
- if (msg == WM_KEYDOWN)
- {
- scan_code = param1 % 128;
- ext = param2 & 0x0100;
- /* left or up arrow */
- if ((scan_code == 75 || scan_code == 72) &&
- (ext || self->wm->num_lock == 0))
- {
- if (self->edit_pos > 0)
+ if (self->popped_from != 0)
{
- self->edit_pos--;
- xrdp_bitmap_invalidate(self, 0);
- }
- }
- /* right or down arrow */
- else if ((scan_code == 77 || scan_code == 80) &&
- (ext || self->wm->num_lock == 0))
- {
- if (self->edit_pos < g_mbstowcs(0, self->caption1, 0))
- {
- self->edit_pos++;
- xrdp_bitmap_invalidate(self, 0);
- }
- }
- /* backspace */
- else if (scan_code == 14)
- {
- n = g_mbstowcs(0, self->caption1, 0);
- if (n > 0)
- {
- if (self->edit_pos > 0)
- {
- self->edit_pos--;
- remove_char_at(self->caption1, 255, self->edit_pos);
- xrdp_bitmap_invalidate(self, 0);
- }
+ /* change height if there are too many items in the list */
+ i = xrdp_painter_text_height(painter, "W");
+ i = self->popped_from->string_list->count * i;
+
+ if (i > self->height)
+ {
+ self->height = i;
+ }
}
- }
- /* delete */
- else if (scan_code == 83 &&
- (ext || self->wm->num_lock == 0))
- {
- n = g_mbstowcs(0, self->caption1, 0);
- if (n > 0)
+
+ painter->fg_color = self->wm->white;
+ xrdp_painter_fill_rect(painter, self, 0, 0, self->width, self->height);
+
+ /* draw the list items */
+ if (self->popped_from != 0)
{
- if (self->edit_pos < n)
- {
- remove_char_at(self->caption1, 255, self->edit_pos);
- xrdp_bitmap_invalidate(self, 0);
- }
+ y = 0;
+
+ for (i = 0; i < self->popped_from->string_list->count; i++)
+ {
+ p = (char *)list_get_item(self->popped_from->string_list, i);
+ h = xrdp_painter_text_height(painter, p);
+ self->item_height = h;
+
+ if (i == self->item_index)
+ {
+ painter->fg_color = self->wm->blue;
+ xrdp_painter_fill_rect(painter, self, 0, y, self->width, h);
+ painter->fg_color = self->wm->white;
+ }
+ else
+ {
+ painter->fg_color = self->wm->black;
+ }
+
+ xrdp_painter_draw_text(painter, self, 2, y, p);
+ y = y + h;
+ }
}
- }
- /* end */
- else if (scan_code == 79 &&
- (ext || self->wm->num_lock == 0))
- {
- n = g_mbstowcs(0, self->caption1, 0);
- if (self->edit_pos < n)
+ }
+
+ /* notify */
+ if (self->notify != 0)
+ {
+ self->notify(self, self, WM_PAINT, (long)painter, 0); /* 3 */
+ }
+
+ /* draw any child windows in the area */
+ for (i = 0; i < self->child_list->count; i++)
+ {
+ b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);
+
+ if (rect == 0)
{
- self->edit_pos = n;
- xrdp_bitmap_invalidate(self, 0);
+ xrdp_bitmap_invalidate(b, 0);
}
- }
- /* home */
- else if ((scan_code == 71) &&
- (ext || (self->wm->num_lock == 0)))
- {
- if (self->edit_pos > 0)
+ else
{
- self->edit_pos = 0;
- xrdp_bitmap_invalidate(self, 0);
+ MAKERECT(r1, b->left, b->top, b->width, b->height);
+
+ if (rect_intersect(rect, &r1, &r2))
+ {
+ RECTOFFSET(r2, -(b->left), -(b->top));
+ xrdp_bitmap_invalidate(b, &r2);
+ }
}
- }
- else
- {
- c = get_char_from_scan_code
- (param2, scan_code, self->wm->keys, self->wm->caps_lock,
- self->wm->num_lock, self->wm->scroll_lock,
- &(self->wm->keymap));
- num_chars = g_mbstowcs(0, self->caption1, 0);
- num_bytes = g_strlen(self->caption1);
- if ((c >= 32) && (num_chars < 127) && (num_bytes < 250))
+ }
+
+ xrdp_painter_end_update(painter);
+ xrdp_painter_delete(painter);
+ return 0;
+}
+
+/*****************************************************************************/
+/* returns error */
+int APP_CC
+xrdp_bitmap_def_proc(struct xrdp_bitmap *self, int msg,
+ int param1, int param2)
+{
+ twchar c;
+ int n;
+ int i;
+ int shift;
+ int ext;
+ int scan_code;
+ int num_bytes;
+ int num_chars;
+ struct xrdp_bitmap *b;
+ struct xrdp_bitmap *focus_out_control;
+
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (self->wm == 0)
+ {
+ return 0;
+ }
+
+ if (self->type == WND_TYPE_WND)
+ {
+ if (msg == WM_KEYDOWN)
{
- add_char_at(self->caption1, 255, c, self->edit_pos);
- self->edit_pos++;
- xrdp_bitmap_invalidate(self, 0);
+ scan_code = param1 % 128;
+
+ if (scan_code == 15) /* tab */
+ {
+ /* move to next tab stop */
+ shift = self->wm->keys[42] || self->wm->keys[54];
+ i = -1;
+
+ if (self->child_list != 0)
+ {
+ i = list_index_of(self->child_list, (long)self->focused_control);
+ }
+
+ if (shift)
+ {
+ i--;
+
+ if (i < 0)
+ {
+ i = self->child_list->count - 1;
+ }
+ }
+ else
+ {
+ i++;
+
+ if (i >= self->child_list->count)
+ {
+ i = 0;
+ }
+ }
+
+ n = self->child_list->count;
+ b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);
+
+ while (b != self->focused_control && b != 0 && n > 0)
+ {
+ n--;
+
+ if (b->tab_stop)
+ {
+ focus_out_control = self->focused_control;
+ self->focused_control = b;
+ xrdp_bitmap_invalidate(focus_out_control, 0);
+ xrdp_bitmap_invalidate(b, 0);
+ break;
+ }
+
+ if (shift)
+ {
+ i--;
+
+ if (i < 0)
+ {
+ i = self->child_list->count - 1;
+ }
+ }
+ else
+ {
+ i++;
+
+ if (i >= self->child_list->count)
+ {
+ i = 0;
+ }
+ }
+
+ b = (struct xrdp_bitmap *)list_get_item(self->child_list, i);
+ }
+ }
+ else if (scan_code == 28) /* enter */
+ {
+ if (self->default_button != 0)
+ {
+ if (self->notify != 0)
+ {
+ /* I think this should use def_proc */
+ self->notify(self, self->default_button, 1, 0, 0);
+ return 0;
+ }
+ }
+ }
+ else if (scan_code == 1) /* esc */
+ {
+ if (self->esc_button != 0)
+ {
+ if (self->notify != 0)
+ {
+ /* I think this should use def_proc */
+ self->notify(self, self->esc_button, 1, 0, 0);
+ return 0;
+ }
+ }
+ }
}
- }
- }
- }
- else if (self->type == WND_TYPE_COMBO)
- {
- if (msg == WM_KEYDOWN)
- {
- scan_code = param1 % 128;
- ext = param2 & 0x0100;
- /* left or up arrow */
- if (((scan_code == 75) || (scan_code == 72)) &&
- (ext || (self->wm->num_lock == 0)))
- {
- if (self->item_index > 0)
+
+ if (self->focused_control != 0)
{
- self->item_index--;
- xrdp_bitmap_invalidate(self, 0);
- if (self->parent->notify != 0)
- {
- self->parent->notify(self->parent, self, CB_ITEMCHANGE, 0, 0);
- }
+ xrdp_bitmap_def_proc(self->focused_control, msg, param1, param2);
}
- }
- /* right or down arrow */
- else if ((scan_code == 77 || scan_code == 80) &&
- (ext || self->wm->num_lock == 0))
- {
- if ((self->item_index + 1) < self->string_list->count)
+ }
+ else if (self->type == WND_TYPE_EDIT)
+ {
+ if (msg == WM_KEYDOWN)
{
- self->item_index++;
- xrdp_bitmap_invalidate(self, 0);
- if (self->parent->notify != 0)
- {
- self->parent->notify(self->parent, self, CB_ITEMCHANGE, 0, 0);
- }
+ scan_code = param1 % 128;
+ ext = param2 & 0x0100;
+
+ /* left or up arrow */
+ if ((scan_code == 75 || scan_code == 72) &&
+ (ext || self->wm->num_lock == 0))
+ {
+ if (self->edit_pos > 0)
+ {
+ self->edit_pos--;
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ /* right or down arrow */
+ else if ((scan_code == 77 || scan_code == 80) &&
+ (ext || self->wm->num_lock == 0))
+ {
+ if (self->edit_pos < g_mbstowcs(0, self->caption1, 0))
+ {
+ self->edit_pos++;
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ /* backspace */
+ else if (scan_code == 14)
+ {
+ n = g_mbstowcs(0, self->caption1, 0);
+
+ if (n > 0)
+ {
+ if (self->edit_pos > 0)
+ {
+ self->edit_pos--;
+ remove_char_at(self->caption1, 255, self->edit_pos);
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ }
+ /* delete */
+ else if (scan_code == 83 &&
+ (ext || self->wm->num_lock == 0))
+ {
+ n = g_mbstowcs(0, self->caption1, 0);
+
+ if (n > 0)
+ {
+ if (self->edit_pos < n)
+ {
+ remove_char_at(self->caption1, 255, self->edit_pos);
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ }
+ /* end */
+ else if (scan_code == 79 &&
+ (ext || self->wm->num_lock == 0))
+ {
+ n = g_mbstowcs(0, self->caption1, 0);
+
+ if (self->edit_pos < n)
+ {
+ self->edit_pos = n;
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ /* home */
+ else if ((scan_code == 71) &&
+ (ext || (self->wm->num_lock == 0)))
+ {
+ if (self->edit_pos > 0)
+ {
+ self->edit_pos = 0;
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ else
+ {
+ c = get_char_from_scan_code
+ (param2, scan_code, self->wm->keys, self->wm->caps_lock,
+ self->wm->num_lock, self->wm->scroll_lock,
+ &(self->wm->keymap));
+ num_chars = g_mbstowcs(0, self->caption1, 0);
+ num_bytes = g_strlen(self->caption1);
+
+ if ((c >= 32) && (num_chars < 127) && (num_bytes < 250))
+ {
+ add_char_at(self->caption1, 255, c, self->edit_pos);
+ self->edit_pos++;
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
}
- }
- }
- }
- else if (self->type == WND_TYPE_SPECIAL)
- {
- if (msg == WM_MOUSEMOVE)
- {
- if (self->item_height > 0 && self->popped_from != 0)
- {
- i = param2;
- i = i / self->item_height;
- if (i != self->item_index &&
- i < self->popped_from->string_list->count)
+ }
+ else if (self->type == WND_TYPE_COMBO)
+ {
+ if (msg == WM_KEYDOWN)
{
- self->item_index = i;
- xrdp_bitmap_invalidate(self, 0);
+ scan_code = param1 % 128;
+ ext = param2 & 0x0100;
+
+ /* left or up arrow */
+ if (((scan_code == 75) || (scan_code == 72)) &&
+ (ext || (self->wm->num_lock == 0)))
+ {
+ if (self->item_index > 0)
+ {
+ self->item_index--;
+ xrdp_bitmap_invalidate(self, 0);
+
+ if (self->parent->notify != 0)
+ {
+ self->parent->notify(self->parent, self, CB_ITEMCHANGE, 0, 0);
+ }
+ }
+ }
+ /* right or down arrow */
+ else if ((scan_code == 77 || scan_code == 80) &&
+ (ext || self->wm->num_lock == 0))
+ {
+ if ((self->item_index + 1) < self->string_list->count)
+ {
+ self->item_index++;
+ xrdp_bitmap_invalidate(self, 0);
+
+ if (self->parent->notify != 0)
+ {
+ self->parent->notify(self->parent, self, CB_ITEMCHANGE, 0, 0);
+ }
+ }
+ }
}
- }
}
- else if (msg == WM_LBUTTONUP)
+ else if (self->type == WND_TYPE_SPECIAL)
{
- if (self->popped_from != 0)
- {
- self->popped_from->item_index = self->item_index;
- xrdp_bitmap_invalidate(self->popped_from, 0);
- if (self->popped_from->parent->notify != 0)
+ if (msg == WM_MOUSEMOVE)
{
- self->popped_from->parent->notify(self->popped_from->parent,
- self->popped_from,
- CB_ITEMCHANGE, 0, 0);
+ if (self->item_height > 0 && self->popped_from != 0)
+ {
+ i = param2;
+ i = i / self->item_height;
+
+ if (i != self->item_index &&
+ i < self->popped_from->string_list->count)
+ {
+ self->item_index = i;
+ xrdp_bitmap_invalidate(self, 0);
+ }
+ }
+ }
+ else if (msg == WM_LBUTTONUP)
+ {
+ if (self->popped_from != 0)
+ {
+ self->popped_from->item_index = self->item_index;
+ xrdp_bitmap_invalidate(self->popped_from, 0);
+
+ if (self->popped_from->parent->notify != 0)
+ {
+ self->popped_from->parent->notify(self->popped_from->parent,
+ self->popped_from,
+ CB_ITEMCHANGE, 0, 0);
+ }
+ }
}
- }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* convert the controls coords to screen coords */
int APP_CC
-xrdp_bitmap_to_screenx(struct xrdp_bitmap* self, int x)
+xrdp_bitmap_to_screenx(struct xrdp_bitmap *self, int x)
{
- int i;
-
- i = x;
- while (self != 0)
- {
- i = i + self->left;
- self = self->parent;
- }
- return i;
+ int i;
+
+ i = x;
+
+ while (self != 0)
+ {
+ i = i + self->left;
+ self = self->parent;
+ }
+
+ return i;
}
/*****************************************************************************/
/* convert the controls coords to screen coords */
int APP_CC
-xrdp_bitmap_to_screeny(struct xrdp_bitmap* self, int y)
+xrdp_bitmap_to_screeny(struct xrdp_bitmap *self, int y)
{
- int i;
-
- i = y;
- while (self != 0)
- {
- i = i + self->top;
- self = self->parent;
- }
- return i;
+ int i;
+
+ i = y;
+
+ while (self != 0)
+ {
+ i = i + self->top;
+ self = self->parent;
+ }
+
+ return i;
}
/*****************************************************************************/
/* convert the screen coords to controls coords */
int APP_CC
-xrdp_bitmap_from_screenx(struct xrdp_bitmap* self, int x)
+xrdp_bitmap_from_screenx(struct xrdp_bitmap *self, int x)
{
- int i;
-
- i = x;
- while (self != 0)
- {
- i = i - self->left;
- self = self->parent;
- }
- return i;
+ int i;
+
+ i = x;
+
+ while (self != 0)
+ {
+ i = i - self->left;
+ self = self->parent;
+ }
+
+ return i;
}
/*****************************************************************************/
/* convert the screen coords to controls coords */
int APP_CC
-xrdp_bitmap_from_screeny(struct xrdp_bitmap* self, int y)
+xrdp_bitmap_from_screeny(struct xrdp_bitmap *self, int y)
{
- int i;
-
- i = y;
- while (self != 0)
- {
- i = i - self->top;
- self = self->parent;
- }
- return i;
+ int i;
+
+ i = y;
+
+ while (self != 0)
+ {
+ i = i - self->top;
+ self = self->parent;
+ }
+
+ return i;
}
/*****************************************************************************/
int APP_CC
-xrdp_bitmap_get_screen_clip(struct xrdp_bitmap* self,
- struct xrdp_painter* painter,
- struct xrdp_rect* rect,
- int* dx, int* dy)
+xrdp_bitmap_get_screen_clip(struct xrdp_bitmap *self,
+ struct xrdp_painter *painter,
+ struct xrdp_rect *rect,
+ int *dx, int *dy)
{
- int ldx;
- int ldy;
-
- if (painter->use_clip)
- {
- *rect = painter->clip;
- }
- else
- {
- rect->left = 0;
- rect->top = 0;
- rect->right = self->width;
- rect->bottom = self->height;
- }
- ldx = xrdp_bitmap_to_screenx(self, 0);
- ldy = xrdp_bitmap_to_screeny(self, 0);
- rect->left += ldx;
- rect->top += ldy;
- rect->right += ldx;
- rect->bottom += ldy;
- if (dx != 0)
- {
- *dx = ldx;
- }
- if (dy != 0)
- {
- *dy = ldy;
- }
- return 0;
+ int ldx;
+ int ldy;
+
+ if (painter->use_clip)
+ {
+ *rect = painter->clip;
+ }
+ else
+ {
+ rect->left = 0;
+ rect->top = 0;
+ rect->right = self->width;
+ rect->bottom = self->height;
+ }
+
+ ldx = xrdp_bitmap_to_screenx(self, 0);
+ ldy = xrdp_bitmap_to_screeny(self, 0);
+ rect->left += ldx;
+ rect->top += ldy;
+ rect->right += ldx;
+ rect->bottom += ldy;
+
+ if (dx != 0)
+ {
+ *dx = ldx;
+ }
+
+ if (dy != 0)
+ {
+ *dy = ldy;
+ }
+
+ return 0;
}
diff --git a/xrdp/xrdp_cache.c b/xrdp/xrdp_cache.c
index 17316633..dfc7e60b 100644
--- a/xrdp/xrdp_cache.c
+++ b/xrdp/xrdp_cache.c
@@ -1,418 +1,451 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- cache
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * cache
+ */
#include "xrdp.h"
/*****************************************************************************/
-struct xrdp_cache* APP_CC
-xrdp_cache_create(struct xrdp_wm* owner,
- struct xrdp_session* session,
- struct xrdp_client_info* client_info)
+struct xrdp_cache *APP_CC
+xrdp_cache_create(struct xrdp_wm *owner,
+ struct xrdp_session *session,
+ struct xrdp_client_info *client_info)
{
- struct xrdp_cache* self;
-
- self = (struct xrdp_cache*)g_malloc(sizeof(struct xrdp_cache), 1);
- self->wm = owner;
- self->session = session;
- self->use_bitmap_comp = client_info->use_bitmap_comp;
- self->cache1_entries = client_info->cache1_entries;
- self->cache1_size = client_info->cache1_size;
- self->cache2_entries = client_info->cache2_entries;
- self->cache2_size = client_info->cache2_size;
- self->cache3_entries = client_info->cache3_entries;
- self->cache3_size = client_info->cache3_size;
- self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;
- self->bitmap_cache_version = client_info->bitmap_cache_version;
- self->pointer_cache_entries = client_info->pointer_cache_entries;
- self->xrdp_os_del_list = list_create();
- return self;
+ struct xrdp_cache *self;
+
+ self = (struct xrdp_cache *)g_malloc(sizeof(struct xrdp_cache), 1);
+ self->wm = owner;
+ self->session = session;
+ self->use_bitmap_comp = client_info->use_bitmap_comp;
+ self->cache1_entries = client_info->cache1_entries;
+ self->cache1_size = client_info->cache1_size;
+ self->cache2_entries = client_info->cache2_entries;
+ self->cache2_size = client_info->cache2_size;
+ self->cache3_entries = client_info->cache3_entries;
+ self->cache3_size = client_info->cache3_size;
+ self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;
+ self->bitmap_cache_version = client_info->bitmap_cache_version;
+ self->pointer_cache_entries = client_info->pointer_cache_entries;
+ self->xrdp_os_del_list = list_create();
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_cache_delete(struct xrdp_cache* self)
+xrdp_cache_delete(struct xrdp_cache *self)
{
- int i;
- int j;
-
- if (self == 0)
- {
- return;
- }
- /* free all the cached bitmaps */
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 2000; j++)
- {
- xrdp_bitmap_delete(self->bitmap_items[i][j].bitmap);
- }
- }
- /* free all the cached font items */
- for (i = 0; i < 12; i++)
- {
- for (j = 0; j < 256; j++)
- {
- g_free(self->char_items[i][j].font_item.data);
- }
- }
- /* free all the off screen bitmaps */
- for (i = 0; i < 2000; i++)
- {
- xrdp_bitmap_delete(self->os_bitmap_items[i].bitmap);
- }
- list_delete(self->xrdp_os_del_list);
-
- g_free(self);
+ int i;
+ int j;
+
+ if (self == 0)
+ {
+ return;
+ }
+
+ /* free all the cached bitmaps */
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 2000; j++)
+ {
+ xrdp_bitmap_delete(self->bitmap_items[i][j].bitmap);
+ }
+ }
+
+ /* free all the cached font items */
+ for (i = 0; i < 12; i++)
+ {
+ for (j = 0; j < 256; j++)
+ {
+ g_free(self->char_items[i][j].font_item.data);
+ }
+ }
+
+ /* free all the off screen bitmaps */
+ for (i = 0; i < 2000; i++)
+ {
+ xrdp_bitmap_delete(self->os_bitmap_items[i].bitmap);
+ }
+
+ list_delete(self->xrdp_os_del_list);
+
+ g_free(self);
}
/*****************************************************************************/
int APP_CC
-xrdp_cache_reset(struct xrdp_cache* self,
- struct xrdp_client_info* client_info)
+xrdp_cache_reset(struct xrdp_cache *self,
+ struct xrdp_client_info *client_info)
{
- struct xrdp_wm* wm;
- struct xrdp_session* session;
- int i;
- int j;
-
- /* free all the cached bitmaps */
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 2000; j++)
- {
- xrdp_bitmap_delete(self->bitmap_items[i][j].bitmap);
- }
- }
- /* free all the cached font items */
- for (i = 0; i < 12; i++)
- {
- for (j = 0; j < 256; j++)
- {
- g_free(self->char_items[i][j].font_item.data);
- }
- }
- /* save these */
- wm = self->wm;
- session = self->session;
- /* set whole struct to zero */
- g_memset(self, 0, sizeof(struct xrdp_cache));
- /* set some stuff back */
- self->wm = wm;
- self->session = session;
- self->use_bitmap_comp = client_info->use_bitmap_comp;
- self->cache1_entries = client_info->cache1_entries;
- self->cache1_size = client_info->cache1_size;
- self->cache2_entries = client_info->cache2_entries;
- self->cache2_size = client_info->cache2_size;
- self->cache3_entries = client_info->cache3_entries;
- self->cache3_size = client_info->cache3_size;
- self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;
- self->bitmap_cache_version = client_info->bitmap_cache_version;
- self->pointer_cache_entries = client_info->pointer_cache_entries;
- return 0;
+ struct xrdp_wm *wm;
+ struct xrdp_session *session;
+ int i;
+ int j;
+
+ /* free all the cached bitmaps */
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 2000; j++)
+ {
+ xrdp_bitmap_delete(self->bitmap_items[i][j].bitmap);
+ }
+ }
+
+ /* free all the cached font items */
+ for (i = 0; i < 12; i++)
+ {
+ for (j = 0; j < 256; j++)
+ {
+ g_free(self->char_items[i][j].font_item.data);
+ }
+ }
+
+ /* save these */
+ wm = self->wm;
+ session = self->session;
+ /* set whole struct to zero */
+ g_memset(self, 0, sizeof(struct xrdp_cache));
+ /* set some stuff back */
+ self->wm = wm;
+ self->session = session;
+ self->use_bitmap_comp = client_info->use_bitmap_comp;
+ self->cache1_entries = client_info->cache1_entries;
+ self->cache1_size = client_info->cache1_size;
+ self->cache2_entries = client_info->cache2_entries;
+ self->cache2_size = client_info->cache2_size;
+ self->cache3_entries = client_info->cache3_entries;
+ self->cache3_size = client_info->cache3_size;
+ self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;
+ self->bitmap_cache_version = client_info->bitmap_cache_version;
+ self->pointer_cache_entries = client_info->pointer_cache_entries;
+ return 0;
}
/*****************************************************************************/
/* returns cache id */
int APP_CC
-xrdp_cache_add_bitmap(struct xrdp_cache* self, struct xrdp_bitmap* bitmap,
+xrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,
int hints)
{
- int i = 0;
- int j = 0;
- int oldest = 0;
- int cache_id = 0;
- int cache_idx = 0;
- int bmp_size = 0;
- int e = 0;
- int Bpp = 0;
-
- e = bitmap->width % 4;
- if (e != 0)
- {
- e = 4 - e;
- }
- Bpp = (bitmap->bpp + 7) / 8;
- bmp_size = (bitmap->width + e) * bitmap->height * Bpp;
- self->bitmap_stamp++;
- /* look for match */
- if (bmp_size <= self->cache1_size)
- {
- i = 0;
- for (j = 0; j < self->cache1_entries; j++)
+ int i = 0;
+ int j = 0;
+ int oldest = 0;
+ int cache_id = 0;
+ int cache_idx = 0;
+ int bmp_size = 0;
+ int e = 0;
+ int Bpp = 0;
+
+ e = bitmap->width % 4;
+
+ if (e != 0)
+ {
+ e = 4 - e;
+ }
+
+ Bpp = (bitmap->bpp + 7) / 8;
+ bmp_size = (bitmap->width + e) * bitmap->height * Bpp;
+ self->bitmap_stamp++;
+
+ /* look for match */
+ if (bmp_size <= self->cache1_size)
{
+ i = 0;
+
+ for (j = 0; j < self->cache1_entries; j++)
+ {
#ifdef USE_CRC
- if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap))
+
+ if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap))
#else
- if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
+ if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
#endif
- {
- self->bitmap_items[i][j].stamp = self->bitmap_stamp;
- DEBUG(("found bitmap at %d %d", i, j));
- xrdp_bitmap_delete(bitmap);
- return MAKELONG(j, i);
- }
- }
- }
- else if (bmp_size <= self->cache2_size)
- {
- i = 1;
- for (j = 0; j < self->cache2_entries; j++)
+ {
+ self->bitmap_items[i][j].stamp = self->bitmap_stamp;
+ DEBUG(("found bitmap at %d %d", i, j));
+ xrdp_bitmap_delete(bitmap);
+ return MAKELONG(j, i);
+ }
+ }
+ }
+ else if (bmp_size <= self->cache2_size)
{
+ i = 1;
+
+ for (j = 0; j < self->cache2_entries; j++)
+ {
#ifdef USE_CRC
- if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap))
+
+ if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap))
#else
- if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
+ if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
#endif
- {
- self->bitmap_items[i][j].stamp = self->bitmap_stamp;
- DEBUG(("found bitmap at %d %d", i, j));
- xrdp_bitmap_delete(bitmap);
- return MAKELONG(j, i);
- }
- }
- }
- else if (bmp_size <= self->cache3_size)
- {
- i = 2;
- for (j = 0; j < self->cache3_entries; j++)
+ {
+ self->bitmap_items[i][j].stamp = self->bitmap_stamp;
+ DEBUG(("found bitmap at %d %d", i, j));
+ xrdp_bitmap_delete(bitmap);
+ return MAKELONG(j, i);
+ }
+ }
+ }
+ else if (bmp_size <= self->cache3_size)
{
+ i = 2;
+
+ for (j = 0; j < self->cache3_entries; j++)
+ {
#ifdef USE_CRC
- if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap))
+
+ if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap))
#else
- if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
+ if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
#endif
- {
- self->bitmap_items[i][j].stamp = self->bitmap_stamp;
- DEBUG(("found bitmap at %d %d", i, j));
- xrdp_bitmap_delete(bitmap);
- return MAKELONG(j, i);
- }
- }
- }
- else
- {
- g_writeln("error in xrdp_cache_add_bitmap, too big(%d)", bmp_size);
- }
- /* look for oldest */
- cache_id = 0;
- cache_idx = 0;
- oldest = 0x7fffffff;
- if (bmp_size <= self->cache1_size)
- {
- i = 0;
- for (j = 0; j < self->cache1_entries; j++)
- {
- if (self->bitmap_items[i][j].stamp < oldest)
- {
- oldest = self->bitmap_items[i][j].stamp;
- cache_id = i;
- cache_idx = j;
- }
- }
- }
- else if (bmp_size <= self->cache2_size)
- {
- i = 1;
- for (j = 0; j < self->cache2_entries; j++)
- {
- if (self->bitmap_items[i][j].stamp < oldest)
- {
- oldest = self->bitmap_items[i][j].stamp;
- cache_id = i;
- cache_idx = j;
- }
- }
- }
- else if (bmp_size <= self->cache3_size)
- {
- i = 2;
- for (j = 0; j < self->cache3_entries; j++)
- {
- if (self->bitmap_items[i][j].stamp < oldest)
- {
- oldest = self->bitmap_items[i][j].stamp;
- cache_id = i;
- cache_idx = j;
- }
- }
- }
- DEBUG(("adding bitmap at %d %d", cache_id, cache_idx));
- /* set, send bitmap and return */
- xrdp_bitmap_delete(self->bitmap_items[cache_id][cache_idx].bitmap);
- self->bitmap_items[cache_id][cache_idx].bitmap = bitmap;
- self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp;
- if (self->use_bitmap_comp)
- {
- if (self->bitmap_cache_version & 4)
- {
- if (libxrdp_orders_send_bitmap3(self->session, bitmap->width,
- bitmap->height, bitmap->bpp,
- bitmap->data, cache_id, cache_idx,
- hints) == 0)
- {
- return MAKELONG(cache_idx, cache_id);
- }
- }
- if (self->bitmap_cache_version & 2)
- {
- libxrdp_orders_send_bitmap2(self->session, bitmap->width,
- bitmap->height, bitmap->bpp,
- bitmap->data, cache_id, cache_idx,
- hints);
- }
- else if (self->bitmap_cache_version & 1)
- {
- libxrdp_orders_send_bitmap(self->session, bitmap->width,
- bitmap->height, bitmap->bpp,
- bitmap->data, cache_id, cache_idx);
- }
- }
- else
- {
- if (self->bitmap_cache_version & 2)
- {
- libxrdp_orders_send_raw_bitmap2(self->session, bitmap->width,
- bitmap->height, bitmap->bpp,
- bitmap->data, cache_id, cache_idx);
- }
- else if (self->bitmap_cache_version & 1)
- {
- libxrdp_orders_send_raw_bitmap(self->session, bitmap->width,
- bitmap->height, bitmap->bpp,
- bitmap->data, cache_id, cache_idx);
- }
- }
- return MAKELONG(cache_idx, cache_id);
+ {
+ self->bitmap_items[i][j].stamp = self->bitmap_stamp;
+ DEBUG(("found bitmap at %d %d", i, j));
+ xrdp_bitmap_delete(bitmap);
+ return MAKELONG(j, i);
+ }
+ }
+ }
+ else
+ {
+ g_writeln("error in xrdp_cache_add_bitmap, too big(%d)", bmp_size);
+ }
+
+ /* look for oldest */
+ cache_id = 0;
+ cache_idx = 0;
+ oldest = 0x7fffffff;
+
+ if (bmp_size <= self->cache1_size)
+ {
+ i = 0;
+
+ for (j = 0; j < self->cache1_entries; j++)
+ {
+ if (self->bitmap_items[i][j].stamp < oldest)
+ {
+ oldest = self->bitmap_items[i][j].stamp;
+ cache_id = i;
+ cache_idx = j;
+ }
+ }
+ }
+ else if (bmp_size <= self->cache2_size)
+ {
+ i = 1;
+
+ for (j = 0; j < self->cache2_entries; j++)
+ {
+ if (self->bitmap_items[i][j].stamp < oldest)
+ {
+ oldest = self->bitmap_items[i][j].stamp;
+ cache_id = i;
+ cache_idx = j;
+ }
+ }
+ }
+ else if (bmp_size <= self->cache3_size)
+ {
+ i = 2;
+
+ for (j = 0; j < self->cache3_entries; j++)
+ {
+ if (self->bitmap_items[i][j].stamp < oldest)
+ {
+ oldest = self->bitmap_items[i][j].stamp;
+ cache_id = i;
+ cache_idx = j;
+ }
+ }
+ }
+
+ DEBUG(("adding bitmap at %d %d", cache_id, cache_idx));
+ /* set, send bitmap and return */
+ xrdp_bitmap_delete(self->bitmap_items[cache_id][cache_idx].bitmap);
+ self->bitmap_items[cache_id][cache_idx].bitmap = bitmap;
+ self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp;
+
+ if (self->use_bitmap_comp)
+ {
+ if (self->bitmap_cache_version & 4)
+ {
+ if (libxrdp_orders_send_bitmap3(self->session, bitmap->width,
+ bitmap->height, bitmap->bpp,
+ bitmap->data, cache_id, cache_idx,
+ hints) == 0)
+ {
+ return MAKELONG(cache_idx, cache_id);
+ }
+ }
+
+ if (self->bitmap_cache_version & 2)
+ {
+ libxrdp_orders_send_bitmap2(self->session, bitmap->width,
+ bitmap->height, bitmap->bpp,
+ bitmap->data, cache_id, cache_idx,
+ hints);
+ }
+ else if (self->bitmap_cache_version & 1)
+ {
+ libxrdp_orders_send_bitmap(self->session, bitmap->width,
+ bitmap->height, bitmap->bpp,
+ bitmap->data, cache_id, cache_idx);
+ }
+ }
+ else
+ {
+ if (self->bitmap_cache_version & 2)
+ {
+ libxrdp_orders_send_raw_bitmap2(self->session, bitmap->width,
+ bitmap->height, bitmap->bpp,
+ bitmap->data, cache_id, cache_idx);
+ }
+ else if (self->bitmap_cache_version & 1)
+ {
+ libxrdp_orders_send_raw_bitmap(self->session, bitmap->width,
+ bitmap->height, bitmap->bpp,
+ bitmap->data, cache_id, cache_idx);
+ }
+ }
+
+ return MAKELONG(cache_idx, cache_id);
}
/*****************************************************************************/
/* not used */
/* not sure how to use a palette in rdp */
int APP_CC
-xrdp_cache_add_palette(struct xrdp_cache* self, int* palette)
+xrdp_cache_add_palette(struct xrdp_cache *self, int *palette)
{
- int i;
- int oldest;
- int index;
+ int i;
+ int oldest;
+ int index;
- if (self == 0)
- {
- return 0;
- }
- if (palette == 0)
- {
- return 0;
- }
- if (self->wm->screen->bpp > 8)
- {
- return 0;
- }
- self->palette_stamp++;
- /* look for match */
- for (i = 0; i < 6; i++)
- {
- if (g_memcmp(palette, self->palette_items[i].palette,
- 256 * sizeof(int)) == 0)
- {
- self->palette_items[i].stamp = self->palette_stamp;
- return i;
- }
- }
- /* look for oldest */
- index = 0;
- oldest = 0x7fffffff;
- for (i = 0; i < 6; i++)
- {
- if (self->palette_items[i].stamp < oldest)
- {
- oldest = self->palette_items[i].stamp;
- index = i;
- }
- }
- /* set, send palette and return */
- g_memcpy(self->palette_items[index].palette, palette, 256 * sizeof(int));
- self->palette_items[index].stamp = self->palette_stamp;
- libxrdp_orders_send_palette(self->session, palette, index);
- return index;
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (palette == 0)
+ {
+ return 0;
+ }
+
+ if (self->wm->screen->bpp > 8)
+ {
+ return 0;
+ }
+
+ self->palette_stamp++;
+
+ /* look for match */
+ for (i = 0; i < 6; i++)
+ {
+ if (g_memcmp(palette, self->palette_items[i].palette,
+ 256 * sizeof(int)) == 0)
+ {
+ self->palette_items[i].stamp = self->palette_stamp;
+ return i;
+ }
+ }
+
+ /* look for oldest */
+ index = 0;
+ oldest = 0x7fffffff;
+
+ for (i = 0; i < 6; i++)
+ {
+ if (self->palette_items[i].stamp < oldest)
+ {
+ oldest = self->palette_items[i].stamp;
+ index = i;
+ }
+ }
+
+ /* set, send palette and return */
+ g_memcpy(self->palette_items[index].palette, palette, 256 * sizeof(int));
+ self->palette_items[index].stamp = self->palette_stamp;
+ libxrdp_orders_send_palette(self->session, palette, index);
+ return index;
}
/*****************************************************************************/
int APP_CC
-xrdp_cache_add_char(struct xrdp_cache* self,
- struct xrdp_font_char* font_item)
+xrdp_cache_add_char(struct xrdp_cache *self,
+ struct xrdp_font_char *font_item)
{
- int i;
- int j;
- int oldest;
- int f;
- int c;
- int datasize;
- struct xrdp_font_char* fi;
-
- self->char_stamp++;
- /* look for match */
- for (i = 7; i < 12; i++)
- {
- for (j = 0; j < 250; j++)
- {
- if (xrdp_font_item_compare(&self->char_items[i][j].font_item, font_item))
- {
- self->char_items[i][j].stamp = self->char_stamp;
- DEBUG(("found font at %d %d", i, j));
- return MAKELONG(j, i);
- }
- }
- }
- /* look for oldest */
- f = 0;
- c = 0;
- oldest = 0x7fffffff;
- for (i = 7; i < 12; i++)
- {
- for (j = 0; j < 250; j++)
- {
- if (self->char_items[i][j].stamp < oldest)
- {
- oldest = self->char_items[i][j].stamp;
- f = i;
- c = j;
- }
- }
- }
- DEBUG(("adding char at %d %d", f, c));
- /* set, send char and return */
- fi = &self->char_items[f][c].font_item;
- g_free(fi->data);
- datasize = FONT_DATASIZE(font_item);
- fi->data = (char*)g_malloc(datasize, 1);
- g_memcpy(fi->data, font_item->data, datasize);
- fi->offset = font_item->offset;
- fi->baseline = font_item->baseline;
- fi->width = font_item->width;
- fi->height = font_item->height;
- self->char_items[f][c].stamp = self->char_stamp;
- libxrdp_orders_send_font(self->session, fi, f, c);
- return MAKELONG(c, f);
+ int i;
+ int j;
+ int oldest;
+ int f;
+ int c;
+ int datasize;
+ struct xrdp_font_char *fi;
+
+ self->char_stamp++;
+
+ /* look for match */
+ for (i = 7; i < 12; i++)
+ {
+ for (j = 0; j < 250; j++)
+ {
+ if (xrdp_font_item_compare(&self->char_items[i][j].font_item, font_item))
+ {
+ self->char_items[i][j].stamp = self->char_stamp;
+ DEBUG(("found font at %d %d", i, j));
+ return MAKELONG(j, i);
+ }
+ }
+ }
+
+ /* look for oldest */
+ f = 0;
+ c = 0;
+ oldest = 0x7fffffff;
+
+ for (i = 7; i < 12; i++)
+ {
+ for (j = 0; j < 250; j++)
+ {
+ if (self->char_items[i][j].stamp < oldest)
+ {
+ oldest = self->char_items[i][j].stamp;
+ f = i;
+ c = j;
+ }
+ }
+ }
+
+ DEBUG(("adding char at %d %d", f, c));
+ /* set, send char and return */
+ fi = &self->char_items[f][c].font_item;
+ g_free(fi->data);
+ datasize = FONT_DATASIZE(font_item);
+ fi->data = (char *)g_malloc(datasize, 1);
+ g_memcpy(fi->data, font_item->data, datasize);
+ fi->offset = font_item->offset;
+ fi->baseline = font_item->baseline;
+ fi->width = font_item->width;
+ fi->height = font_item->height;
+ self->char_items[f][c].stamp = self->char_stamp;
+ libxrdp_orders_send_font(self->session, fi, f, c);
+ return MAKELONG(c, f);
}
/*****************************************************************************/
@@ -421,191 +454,208 @@ xrdp_cache_add_char(struct xrdp_cache* self,
returns the index in the cache
does not take ownership of pointer_item */
int APP_CC
-xrdp_cache_add_pointer(struct xrdp_cache* self,
- struct xrdp_pointer_item* pointer_item)
+xrdp_cache_add_pointer(struct xrdp_cache *self,
+ struct xrdp_pointer_item *pointer_item)
{
- int i;
- int oldest;
- int index;
+ int i;
+ int oldest;
+ int index;
- if (self == 0)
- {
- return 0;
- }
- self->pointer_stamp++;
- /* look for match */
- for (i = 2; i < self->pointer_cache_entries; i++)
- {
- if (self->pointer_items[i].x == pointer_item->x &&
- self->pointer_items[i].y == pointer_item->y &&
- g_memcmp(self->pointer_items[i].data,
- pointer_item->data, 32 * 32 * 3) == 0 &&
- g_memcmp(self->pointer_items[i].mask,
- pointer_item->mask, 32 * 32 / 8) == 0)
- {
- self->pointer_items[i].stamp = self->pointer_stamp;
- xrdp_wm_set_pointer(self->wm, i);
- self->wm->current_pointer = i;
- DEBUG(("found pointer at %d", i));
- return i;
- }
- }
- /* look for oldest */
- index = 2;
- oldest = 0x7fffffff;
- for (i = 2; i < self->pointer_cache_entries; i++)
- {
- if (self->pointer_items[i].stamp < oldest)
- {
- oldest = self->pointer_items[i].stamp;
- index = i;
- }
- }
- self->pointer_items[index].x = pointer_item->x;
- self->pointer_items[index].y = pointer_item->y;
- g_memcpy(self->pointer_items[index].data,
- pointer_item->data, 32 * 32 * 3);
- g_memcpy(self->pointer_items[index].mask,
- pointer_item->mask, 32 * 32 / 8);
- self->pointer_items[index].stamp = self->pointer_stamp;
- xrdp_wm_send_pointer(self->wm, index,
- self->pointer_items[index].data,
- self->pointer_items[index].mask,
- self->pointer_items[index].x,
- self->pointer_items[index].y);
- self->wm->current_pointer = index;
- DEBUG(("adding pointer at %d", index));
- return index;
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ self->pointer_stamp++;
+
+ /* look for match */
+ for (i = 2; i < self->pointer_cache_entries; i++)
+ {
+ if (self->pointer_items[i].x == pointer_item->x &&
+ self->pointer_items[i].y == pointer_item->y &&
+ g_memcmp(self->pointer_items[i].data,
+ pointer_item->data, 32 * 32 * 3) == 0 &&
+ g_memcmp(self->pointer_items[i].mask,
+ pointer_item->mask, 32 * 32 / 8) == 0)
+ {
+ self->pointer_items[i].stamp = self->pointer_stamp;
+ xrdp_wm_set_pointer(self->wm, i);
+ self->wm->current_pointer = i;
+ DEBUG(("found pointer at %d", i));
+ return i;
+ }
+ }
+
+ /* look for oldest */
+ index = 2;
+ oldest = 0x7fffffff;
+
+ for (i = 2; i < self->pointer_cache_entries; i++)
+ {
+ if (self->pointer_items[i].stamp < oldest)
+ {
+ oldest = self->pointer_items[i].stamp;
+ index = i;
+ }
+ }
+
+ self->pointer_items[index].x = pointer_item->x;
+ self->pointer_items[index].y = pointer_item->y;
+ g_memcpy(self->pointer_items[index].data,
+ pointer_item->data, 32 * 32 * 3);
+ g_memcpy(self->pointer_items[index].mask,
+ pointer_item->mask, 32 * 32 / 8);
+ self->pointer_items[index].stamp = self->pointer_stamp;
+ xrdp_wm_send_pointer(self->wm, index,
+ self->pointer_items[index].data,
+ self->pointer_items[index].mask,
+ self->pointer_items[index].x,
+ self->pointer_items[index].y);
+ self->wm->current_pointer = index;
+ DEBUG(("adding pointer at %d", index));
+ return index;
}
/*****************************************************************************/
/* this does not take owership of pointer_item, it makes a copy */
int APP_CC
-xrdp_cache_add_pointer_static(struct xrdp_cache* self,
- struct xrdp_pointer_item* pointer_item,
+xrdp_cache_add_pointer_static(struct xrdp_cache *self,
+ struct xrdp_pointer_item *pointer_item,
int index)
{
- if (self == 0)
- {
- return 0;
- }
- self->pointer_items[index].x = pointer_item->x;
- self->pointer_items[index].y = pointer_item->y;
- g_memcpy(self->pointer_items[index].data,
- pointer_item->data, 32 * 32 * 3);
- g_memcpy(self->pointer_items[index].mask,
- pointer_item->mask, 32 * 32 / 8);
- self->pointer_items[index].stamp = self->pointer_stamp;
- xrdp_wm_send_pointer(self->wm, index,
- self->pointer_items[index].data,
- self->pointer_items[index].mask,
- self->pointer_items[index].x,
- self->pointer_items[index].y);
- self->wm->current_pointer = index;
- DEBUG(("adding pointer at %d", index));
- return index;
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ self->pointer_items[index].x = pointer_item->x;
+ self->pointer_items[index].y = pointer_item->y;
+ g_memcpy(self->pointer_items[index].data,
+ pointer_item->data, 32 * 32 * 3);
+ g_memcpy(self->pointer_items[index].mask,
+ pointer_item->mask, 32 * 32 / 8);
+ self->pointer_items[index].stamp = self->pointer_stamp;
+ xrdp_wm_send_pointer(self->wm, index,
+ self->pointer_items[index].data,
+ self->pointer_items[index].mask,
+ self->pointer_items[index].x,
+ self->pointer_items[index].y);
+ self->wm->current_pointer = index;
+ DEBUG(("adding pointer at %d", index));
+ return index;
}
/*****************************************************************************/
/* this does not take owership of brush_item_data, it makes a copy */
int APP_CC
-xrdp_cache_add_brush(struct xrdp_cache* self,
- char* brush_item_data)
+xrdp_cache_add_brush(struct xrdp_cache *self,
+ char *brush_item_data)
{
- int i;
- int oldest;
- int index;
+ int i;
+ int oldest;
+ int index;
- if (self == 0)
- {
- return 0;
- }
- self->brush_stamp++;
- /* look for match */
- for (i = 0; i < 64; i++)
- {
- if (g_memcmp(self->brush_items[i].pattern,
- brush_item_data, 8) == 0)
- {
- self->brush_items[i].stamp = self->brush_stamp;
- DEBUG(("found brush at %d", i));
- return i;
- }
- }
- /* look for oldest */
- index = 0;
- oldest = 0x7fffffff;
- for (i = 0; i < 64; i++)
- {
- if (self->brush_items[i].stamp < oldest)
- {
- oldest = self->brush_items[i].stamp;
- index = i;
- }
- }
- g_memcpy(self->brush_items[index].pattern,
- brush_item_data, 8);
- self->brush_items[index].stamp = self->brush_stamp;
- libxrdp_orders_send_brush(self->session, 8, 8, 1, 0x81, 8,
- self->brush_items[index].pattern, index);
- DEBUG(("adding brush at %d", index));
- return index;
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ self->brush_stamp++;
+
+ /* look for match */
+ for (i = 0; i < 64; i++)
+ {
+ if (g_memcmp(self->brush_items[i].pattern,
+ brush_item_data, 8) == 0)
+ {
+ self->brush_items[i].stamp = self->brush_stamp;
+ DEBUG(("found brush at %d", i));
+ return i;
+ }
+ }
+
+ /* look for oldest */
+ index = 0;
+ oldest = 0x7fffffff;
+
+ for (i = 0; i < 64; i++)
+ {
+ if (self->brush_items[i].stamp < oldest)
+ {
+ oldest = self->brush_items[i].stamp;
+ index = i;
+ }
+ }
+
+ g_memcpy(self->brush_items[index].pattern,
+ brush_item_data, 8);
+ self->brush_items[index].stamp = self->brush_stamp;
+ libxrdp_orders_send_brush(self->session, 8, 8, 1, 0x81, 8,
+ self->brush_items[index].pattern, index);
+ DEBUG(("adding brush at %d", index));
+ return index;
}
/*****************************************************************************/
/* returns error */
int APP_CC
-xrdp_cache_add_os_bitmap(struct xrdp_cache* self, struct xrdp_bitmap* bitmap,
+xrdp_cache_add_os_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,
int rdpindex)
{
- struct xrdp_os_bitmap_item* bi;
-
- if ((rdpindex < 0) || (rdpindex >= 2000))
- {
- return 1;
- }
- bi = self->os_bitmap_items + rdpindex;
- bi->bitmap = bitmap;
- return 0;
+ struct xrdp_os_bitmap_item *bi;
+
+ if ((rdpindex < 0) || (rdpindex >= 2000))
+ {
+ return 1;
+ }
+
+ bi = self->os_bitmap_items + rdpindex;
+ bi->bitmap = bitmap;
+ return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
-xrdp_cache_remove_os_bitmap(struct xrdp_cache* self, int rdpindex)
+xrdp_cache_remove_os_bitmap(struct xrdp_cache *self, int rdpindex)
{
- struct xrdp_os_bitmap_item* bi;
- int index;
-
- if ((rdpindex < 0) || (rdpindex >= 2000))
- {
- return 1;
- }
- bi = self->os_bitmap_items + rdpindex;
- if (bi->bitmap->tab_stop)
- {
- index = list_index_of(self->xrdp_os_del_list, rdpindex);
- if (index == -1)
- {
- list_add_item(self->xrdp_os_del_list, rdpindex);
- }
- }
- xrdp_bitmap_delete(bi->bitmap);
- g_memset(bi, 0, sizeof(struct xrdp_os_bitmap_item));
- return 0;
+ struct xrdp_os_bitmap_item *bi;
+ int index;
+
+ if ((rdpindex < 0) || (rdpindex >= 2000))
+ {
+ return 1;
+ }
+
+ bi = self->os_bitmap_items + rdpindex;
+
+ if (bi->bitmap->tab_stop)
+ {
+ index = list_index_of(self->xrdp_os_del_list, rdpindex);
+
+ if (index == -1)
+ {
+ list_add_item(self->xrdp_os_del_list, rdpindex);
+ }
+ }
+
+ xrdp_bitmap_delete(bi->bitmap);
+ g_memset(bi, 0, sizeof(struct xrdp_os_bitmap_item));
+ return 0;
}
/*****************************************************************************/
-struct xrdp_os_bitmap_item* APP_CC
-xrdp_cache_get_os_bitmap(struct xrdp_cache* self, int rdpindex)
+struct xrdp_os_bitmap_item *APP_CC
+xrdp_cache_get_os_bitmap(struct xrdp_cache *self, int rdpindex)
{
- struct xrdp_os_bitmap_item* bi;
+ struct xrdp_os_bitmap_item *bi;
- if ((rdpindex < 0) || (rdpindex >= 2000))
- {
- return 0;
- }
- bi = self->os_bitmap_items + rdpindex;
- return bi;
+ if ((rdpindex < 0) || (rdpindex >= 2000))
+ {
+ return 0;
+ }
+
+ bi = self->os_bitmap_items + rdpindex;
+ return bi;
}
diff --git a/xrdp/xrdp_font.c b/xrdp/xrdp_font.c
index e1c4257b..91734807 100644
--- a/xrdp/xrdp_font.c
+++ b/xrdp/xrdp_font.c
@@ -1,26 +1,24 @@
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * fonts
+ */
/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- fonts
-
-*/
-/*
The fv1 files contain
Font File Header (just one)
FNT1 4 bytes
@@ -43,176 +41,197 @@
#if 0 /* not used */
static char w_char[] =
{
- 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00,
- 0x08, 0x20, 0x80,
- 0x08, 0x50, 0x80,
- 0x04, 0x51, 0x00,
- 0x04, 0x51, 0x00,
- 0x04, 0x51, 0x00,
- 0x02, 0x8a, 0x00,
- 0x02, 0x8a, 0x00,
- 0x02, 0x8a, 0x00,
- 0x01, 0x04, 0x00,
- 0x01, 0x04, 0x00,
- 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x08, 0x20, 0x80,
+ 0x08, 0x50, 0x80,
+ 0x04, 0x51, 0x00,
+ 0x04, 0x51, 0x00,
+ 0x04, 0x51, 0x00,
+ 0x02, 0x8a, 0x00,
+ 0x02, 0x8a, 0x00,
+ 0x02, 0x8a, 0x00,
+ 0x01, 0x04, 0x00,
+ 0x01, 0x04, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00,
};
#endif
/*****************************************************************************/
-struct xrdp_font* APP_CC
-xrdp_font_create(struct xrdp_wm* wm)
+struct xrdp_font *APP_CC
+xrdp_font_create(struct xrdp_wm *wm)
{
- struct xrdp_font* self;
- struct stream* s;
- int fd;
- int b;
- int i;
- int index;
- int datasize;
- int file_size;
- struct xrdp_font_char* f;
- char file_path[256];
-
- DEBUG(("in xrdp_font_create"));
- g_snprintf(file_path, 255, "%s/%s", XRDP_SHARE_PATH, DEFAULT_FONT_NAME);
- if (!g_file_exist(file_path))
- {
- g_writeln("xrdp_font_create: error font file [%s] does not exist",
- file_path);
- return 0;
- }
- file_size = g_file_get_size(file_path);
- if (file_size < 1)
- {
- g_writeln("xrdp_font_create: error reading font from file [%s]",
- file_path);
- return 0;
- }
- self = (struct xrdp_font*)g_malloc(sizeof(struct xrdp_font), 1);
- self->wm = wm;
- make_stream(s);
- init_stream(s, file_size + 1024);
- fd = g_file_open(file_path);
- if (fd != -1)
- {
- b = g_file_read(fd, s->data, file_size + 1024);
- g_file_close(fd);
- if (b > 0)
+ struct xrdp_font *self;
+ struct stream *s;
+ int fd;
+ int b;
+ int i;
+ int index;
+ int datasize;
+ int file_size;
+ struct xrdp_font_char *f;
+ char file_path[256];
+
+ DEBUG(("in xrdp_font_create"));
+ g_snprintf(file_path, 255, "%s/%s", XRDP_SHARE_PATH, DEFAULT_FONT_NAME);
+
+ if (!g_file_exist(file_path))
{
- s->end = s->data + b;
- in_uint8s(s, 4);
- in_uint8a(s, self->name, 32);
- in_uint16_le(s, self->size);
- in_uint16_le(s, self->style);
- in_uint8s(s, 8);
- index = 32;
- while (s_check_rem(s, 16))
- {
- f = self->font_items + index;
- in_sint16_le(s, i);
- f->width = i;
- in_sint16_le(s, i);
- f->height = i;
- in_sint16_le(s, i);
- f->baseline = i;
- in_sint16_le(s, i);
- f->offset = i;
- in_sint16_le(s, i);
- f->incby = i;
- in_uint8s(s, 6);
- datasize = FONT_DATASIZE(f);
- if (datasize < 0 || datasize > 512)
- {
- /* shouldn't happen */
- g_writeln("error in xrdp_font_create, datasize wrong");
- g_writeln("width %d height %d datasize %d index %d",
- f->width, f->height, datasize, index);
- break;
- }
- if (s_check_rem(s, datasize))
- {
- f->data = (char*)g_malloc(datasize, 0);
- in_uint8a(s, f->data, datasize);
- }
- else
+ g_writeln("xrdp_font_create: error font file [%s] does not exist",
+ file_path);
+ return 0;
+ }
+
+ file_size = g_file_get_size(file_path);
+
+ if (file_size < 1)
+ {
+ g_writeln("xrdp_font_create: error reading font from file [%s]",
+ file_path);
+ return 0;
+ }
+
+ self = (struct xrdp_font *)g_malloc(sizeof(struct xrdp_font), 1);
+ self->wm = wm;
+ make_stream(s);
+ init_stream(s, file_size + 1024);
+ fd = g_file_open(file_path);
+
+ if (fd != -1)
+ {
+ b = g_file_read(fd, s->data, file_size + 1024);
+ g_file_close(fd);
+
+ if (b > 0)
{
- g_writeln("error in xrdp_font_create");
+ s->end = s->data + b;
+ in_uint8s(s, 4);
+ in_uint8a(s, self->name, 32);
+ in_uint16_le(s, self->size);
+ in_uint16_le(s, self->style);
+ in_uint8s(s, 8);
+ index = 32;
+
+ while (s_check_rem(s, 16))
+ {
+ f = self->font_items + index;
+ in_sint16_le(s, i);
+ f->width = i;
+ in_sint16_le(s, i);
+ f->height = i;
+ in_sint16_le(s, i);
+ f->baseline = i;
+ in_sint16_le(s, i);
+ f->offset = i;
+ in_sint16_le(s, i);
+ f->incby = i;
+ in_uint8s(s, 6);
+ datasize = FONT_DATASIZE(f);
+
+ if (datasize < 0 || datasize > 512)
+ {
+ /* shouldn't happen */
+ g_writeln("error in xrdp_font_create, datasize wrong");
+ g_writeln("width %d height %d datasize %d index %d",
+ f->width, f->height, datasize, index);
+ break;
+ }
+
+ if (s_check_rem(s, datasize))
+ {
+ f->data = (char *)g_malloc(datasize, 0);
+ in_uint8a(s, f->data, datasize);
+ }
+ else
+ {
+ g_writeln("error in xrdp_font_create");
+ }
+
+ index++;
+ }
}
- index++;
- }
}
- }
- free_stream(s);
-/*
- self->font_items[0].offset = -4;
- self->font_items[0].baseline = -16;
- self->font_items[0].width = 24;
- self->font_items[0].height = 16;
- self->font_items[0].data = g_malloc(3 * 16, 0);
- g_memcpy(self->font_items[0].data, w_char, 3 * 16);
-*/
- DEBUG(("out xrdp_font_create"));
- return self;
+
+ free_stream(s);
+ /*
+ self->font_items[0].offset = -4;
+ self->font_items[0].baseline = -16;
+ self->font_items[0].width = 24;
+ self->font_items[0].height = 16;
+ self->font_items[0].data = g_malloc(3 * 16, 0);
+ g_memcpy(self->font_items[0].data, w_char, 3 * 16);
+ */
+ DEBUG(("out xrdp_font_create"));
+ return self;
}
/*****************************************************************************/
/* free the font and all the items */
void APP_CC
-xrdp_font_delete(struct xrdp_font* self)
+xrdp_font_delete(struct xrdp_font *self)
{
- int i;
-
- if (self == 0)
- {
- return;
- }
- for (i = 0; i < NUM_FONTS; i++)
- {
- g_free(self->font_items[i].data);
- }
- g_free(self);
+ int i;
+
+ if (self == 0)
+ {
+ return;
+ }
+
+ for (i = 0; i < NUM_FONTS; i++)
+ {
+ g_free(self->font_items[i].data);
+ }
+
+ g_free(self);
}
/*****************************************************************************/
/* compare the two font items returns 1 if they match */
int APP_CC
-xrdp_font_item_compare(struct xrdp_font_char* font1,
- struct xrdp_font_char* font2)
+xrdp_font_item_compare(struct xrdp_font_char *font1,
+ struct xrdp_font_char *font2)
{
- int datasize;
+ int datasize;
+
+ if (font1 == 0)
+ {
+ return 0;
+ }
+
+ if (font2 == 0)
+ {
+ return 0;
+ }
+
+ if (font1->offset != font2->offset)
+ {
+ return 0;
+ }
+
+ if (font1->baseline != font2->baseline)
+ {
+ return 0;
+ }
+
+ if (font1->width != font2->width)
+ {
+ return 0;
+ }
+
+ if (font1->height != font2->height)
+ {
+ return 0;
+ }
+
+ datasize = FONT_DATASIZE(font1);
+
+ if (g_memcmp(font1->data, font2->data, datasize) == 0)
+ {
+ return 1;
+ }
- if (font1 == 0)
- {
- return 0;
- }
- if (font2 == 0)
- {
- return 0;
- }
- if (font1->offset != font2->offset)
- {
- return 0;
- }
- if (font1->baseline != font2->baseline)
- {
- return 0;
- }
- if (font1->width != font2->width)
- {
- return 0;
- }
- if (font1->height != font2->height)
- {
return 0;
- }
- datasize = FONT_DATASIZE(font1);
- if (g_memcmp(font1->data, font2->data, datasize) == 0)
- {
- return 1;
- }
- return 0;
}
diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c
index 82bade84..5de6f51a 100644
--- a/xrdp/xrdp_listen.c
+++ b/xrdp/xrdp_listen.c
@@ -1,429 +1,476 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- listen for incoming connection
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * listen for incoming connection
+ */
#include "xrdp.h"
/* 'g_process' is protected by the semaphore 'g_process_sem'. One thread sets
g_process and waits for the other to process it */
static tbus g_process_sem = 0;
-static struct xrdp_process* g_process = 0;
+static struct xrdp_process *g_process = 0;
/*****************************************************************************/
static int
-xrdp_listen_create_pro_done(struct xrdp_listen* self)
+xrdp_listen_create_pro_done(struct xrdp_listen *self)
{
- int pid;
- char text[256];
-
- pid = g_getpid();
- g_snprintf(text, 255, "xrdp_%8.8x_listen_pro_done_event", pid);
- self->pro_done_event = g_create_wait_obj(text);
- if(self->pro_done_event == 0)
- {
- g_writeln("Failure creating pro_done_event");
- }
- return 0;
+ int pid;
+ char text[256];
+
+ pid = g_getpid();
+ g_snprintf(text, 255, "xrdp_%8.8x_listen_pro_done_event", pid);
+ self->pro_done_event = g_create_wait_obj(text);
+
+ if (self->pro_done_event == 0)
+ {
+ g_writeln("Failure creating pro_done_event");
+ }
+
+ return 0;
}
/*****************************************************************************/
-struct xrdp_listen* APP_CC
+struct xrdp_listen *APP_CC
xrdp_listen_create(void)
{
- struct xrdp_listen* self;
-
- self = (struct xrdp_listen*)g_malloc(sizeof(struct xrdp_listen), 1);
- xrdp_listen_create_pro_done(self);
- self->process_list = list_create();
- if (g_process_sem == 0)
- {
- g_process_sem = tc_sem_create(0);
- }
- self->listen_trans = trans_create(TRANS_MODE_TCP, 16, 16);
- if (self->listen_trans == 0)
- {
- g_writeln("xrdp_listen_create: trans_create failed");
- }
- return self;
+ struct xrdp_listen *self;
+
+ self = (struct xrdp_listen *)g_malloc(sizeof(struct xrdp_listen), 1);
+ xrdp_listen_create_pro_done(self);
+ self->process_list = list_create();
+
+ if (g_process_sem == 0)
+ {
+ g_process_sem = tc_sem_create(0);
+ }
+
+ self->listen_trans = trans_create(TRANS_MODE_TCP, 16, 16);
+
+ if (self->listen_trans == 0)
+ {
+ g_writeln("xrdp_listen_create: trans_create failed");
+ }
+
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_listen_delete(struct xrdp_listen* self)
+xrdp_listen_delete(struct xrdp_listen *self)
{
- if (self->listen_trans != 0)
- {
- trans_delete(self->listen_trans);
- }
- if (g_process_sem != 0)
- {
- tc_sem_delete(g_process_sem);
- g_process_sem = 0;
- }
- g_delete_wait_obj(self->pro_done_event);
- list_delete(self->process_list);
- g_free(self);
+ if (self->listen_trans != 0)
+ {
+ trans_delete(self->listen_trans);
+ }
+
+ if (g_process_sem != 0)
+ {
+ tc_sem_delete(g_process_sem);
+ g_process_sem = 0;
+ }
+
+ g_delete_wait_obj(self->pro_done_event);
+ list_delete(self->process_list);
+ g_free(self);
}
/*****************************************************************************/
/* returns error */
static int APP_CC
-xrdp_listen_add_pro(struct xrdp_listen* self, struct xrdp_process* process)
+xrdp_listen_add_pro(struct xrdp_listen *self, struct xrdp_process *process)
{
- list_add_item(self->process_list, (tbus)process);
- return 0;
+ list_add_item(self->process_list, (tbus)process);
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_listen_delete_done_pro(struct xrdp_listen* self)
+xrdp_listen_delete_done_pro(struct xrdp_listen *self)
{
- int i;
- struct xrdp_process* pro;
+ int i;
+ struct xrdp_process *pro;
- for (i = self->process_list->count - 1; i >= 0; i--)
- {
- pro = (struct xrdp_process*)list_get_item(self->process_list, i);
- if (pro != 0)
+ for (i = self->process_list->count - 1; i >= 0; i--)
{
- if (pro->status < 0)
- {
- xrdp_process_delete(pro);
- list_remove_item(self->process_list, i);
- }
+ pro = (struct xrdp_process *)list_get_item(self->process_list, i);
+
+ if (pro != 0)
+ {
+ if (pro->status < 0)
+ {
+ xrdp_process_delete(pro);
+ list_remove_item(self->process_list, i);
+ }
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* i can't get stupid in_val to work, hum using global var for now */
THREAD_RV THREAD_CC
-xrdp_process_run(void* in_val)
+xrdp_process_run(void *in_val)
{
- struct xrdp_process* process;
-
- DEBUG(("process started"));
- process = g_process;
- g_process = 0;
- tc_sem_inc(g_process_sem);
- xrdp_process_main_loop(process);
- DEBUG(("process done"));
- return 0;
+ struct xrdp_process *process;
+
+ DEBUG(("process started"));
+ process = g_process;
+ g_process = 0;
+ tc_sem_inc(g_process_sem);
+ xrdp_process_main_loop(process);
+ DEBUG(("process done"));
+ return 0;
}
/*****************************************************************************/
static int
-xrdp_listen_get_port_address(char* port, int port_bytes,
- char* address, int address_bytes,
+xrdp_listen_get_port_address(char *port, int port_bytes,
+ char *address, int address_bytes,
int *tcp_nodelay, int *tcp_keepalive,
- struct xrdp_startup_params* startup_param)
+ struct xrdp_startup_params *startup_param)
{
- int fd;
- int error;
- int index;
- char* val;
- struct list* names;
- struct list* values;
- char cfg_file[256];
-
- /* default to port 3389 */
- g_strncpy(port, "3389", port_bytes - 1);
- /* Default to all */
- g_strncpy(address, "0.0.0.0", address_bytes - 1);
- /* see if port or address is in xrdp.ini file */
- g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
- fd = g_file_open(cfg_file);
- *tcp_nodelay = 0 ;
- *tcp_keepalive = 0 ;
- if (fd > 0)
- {
- names = list_create();
- names->auto_free = 1;
- values = list_create();
- values->auto_free = 1;
- if (file_read_section(fd, "globals", names, values) == 0)
+ int fd;
+ int error;
+ int index;
+ char *val;
+ struct list *names;
+ struct list *values;
+ char cfg_file[256];
+
+ /* default to port 3389 */
+ g_strncpy(port, "3389", port_bytes - 1);
+ /* Default to all */
+ g_strncpy(address, "0.0.0.0", address_bytes - 1);
+ /* see if port or address is in xrdp.ini file */
+ g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+ fd = g_file_open(cfg_file);
+ *tcp_nodelay = 0 ;
+ *tcp_keepalive = 0 ;
+
+ if (fd > 0)
{
- for (index = 0; index < names->count; index++)
- {
- val = (char*)list_get_item(names, index);
- if (val != 0)
+ names = list_create();
+ names->auto_free = 1;
+ values = list_create();
+ values->auto_free = 1;
+
+ if (file_read_section(fd, "globals", names, values) == 0)
{
- if (g_strcasecmp(val, "port") == 0)
- {
- val = (char*)list_get_item(values, index);
- error = g_atoi(val);
- if ((error > 0) && (error < 65000))
- {
- g_strncpy(port, val, port_bytes - 1);
- }
- }
- if (g_strcasecmp(val, "address") == 0)
- {
- val = (char*)list_get_item(values, index);
- g_strncpy(address, val, address_bytes - 1);
- }
- if (g_strcasecmp(val, "fork") == 0)
- {
- val = (char*)list_get_item(values, index);
- if ((g_strcasecmp(val, "yes") == 0) ||
- (g_strcasecmp(val, "on") == 0) ||
- (g_strcasecmp(val, "true") == 0) ||
- (g_atoi(val) != 0))
+ for (index = 0; index < names->count; index++)
{
- startup_param->fork = 1;
- }
- }
- if (g_strcasecmp(val, "tcp_nodelay") == 0)
- {
- val = (char*)list_get_item(values, index);
- if ((g_strcasecmp(val, "yes") == 0) ||
- (g_strcasecmp(val, "on") == 0) ||
- (g_strcasecmp(val, "true") == 0) ||
- (g_atoi(val) != 0))
- {
- *tcp_nodelay = 1 ;
- }
- }
- if (g_strcasecmp(val, "tcp_keepalive") == 0)
- {
- val = (char*)list_get_item(values, index);
- if ((g_strcasecmp(val, "yes") == 0) ||
- (g_strcasecmp(val, "on") == 0) ||
- (g_strcasecmp(val, "true") == 0) ||
- (g_atoi(val) != 0))
- {
- *tcp_keepalive = 1 ;
+ val = (char *)list_get_item(names, index);
+
+ if (val != 0)
+ {
+ if (g_strcasecmp(val, "port") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ error = g_atoi(val);
+
+ if ((error > 0) && (error < 65000))
+ {
+ g_strncpy(port, val, port_bytes - 1);
+ }
+ }
+
+ if (g_strcasecmp(val, "address") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ g_strncpy(address, val, address_bytes - 1);
+ }
+
+ if (g_strcasecmp(val, "fork") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+
+ if ((g_strcasecmp(val, "yes") == 0) ||
+ (g_strcasecmp(val, "on") == 0) ||
+ (g_strcasecmp(val, "true") == 0) ||
+ (g_atoi(val) != 0))
+ {
+ startup_param->fork = 1;
+ }
+ }
+
+ if (g_strcasecmp(val, "tcp_nodelay") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+
+ if ((g_strcasecmp(val, "yes") == 0) ||
+ (g_strcasecmp(val, "on") == 0) ||
+ (g_strcasecmp(val, "true") == 0) ||
+ (g_atoi(val) != 0))
+ {
+ *tcp_nodelay = 1 ;
+ }
+ }
+
+ if (g_strcasecmp(val, "tcp_keepalive") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+
+ if ((g_strcasecmp(val, "yes") == 0) ||
+ (g_strcasecmp(val, "on") == 0) ||
+ (g_strcasecmp(val, "true") == 0) ||
+ (g_atoi(val) != 0))
+ {
+ *tcp_keepalive = 1 ;
+ }
+ }
+ }
}
- }
}
- }
+
+ list_delete(names);
+ list_delete(values);
+ g_file_close(fd);
}
- list_delete(names);
- list_delete(values);
- g_file_close(fd);
- }
- /* startup_param overrides */
- if (startup_param->port[0] != 0)
- {
- g_strncpy(port, startup_param->port, port_bytes - 1);
- }
- return 0;
+
+ /* startup_param overrides */
+ if (startup_param->port[0] != 0)
+ {
+ g_strncpy(port, startup_param->port, port_bytes - 1);
+ }
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_listen_fork(struct xrdp_listen* self, struct trans* server_trans)
+xrdp_listen_fork(struct xrdp_listen *self, struct trans *server_trans)
{
- int pid;
- struct xrdp_process* process;
-
- pid = g_fork();
- if (pid == 0)
- {
- /* child */
- /* recreate some main globals */
- xrdp_child_fork();
- /* recreate the process done wait object, not used in fork mode */
- /* close, don't delete this */
- g_close_wait_obj(self->pro_done_event);
- xrdp_listen_create_pro_done(self);
- /* delete listener, child need not listen */
- trans_delete(self->listen_trans);
- self->listen_trans = 0;
- /* new connect instance */
- process = xrdp_process_create(self, 0);
- process->server_trans = server_trans;
- g_process = process;
- xrdp_process_run(0);
- xrdp_process_delete(process);
- /* mark this process to exit */
- g_set_term(1);
+ int pid;
+ struct xrdp_process *process;
+
+ pid = g_fork();
+
+ if (pid == 0)
+ {
+ /* child */
+ /* recreate some main globals */
+ xrdp_child_fork();
+ /* recreate the process done wait object, not used in fork mode */
+ /* close, don't delete this */
+ g_close_wait_obj(self->pro_done_event);
+ xrdp_listen_create_pro_done(self);
+ /* delete listener, child need not listen */
+ trans_delete(self->listen_trans);
+ self->listen_trans = 0;
+ /* new connect instance */
+ process = xrdp_process_create(self, 0);
+ process->server_trans = server_trans;
+ g_process = process;
+ xrdp_process_run(0);
+ xrdp_process_delete(process);
+ /* mark this process to exit */
+ g_set_term(1);
+ return 0;
+ }
+
+ /* parent */
+ trans_delete(server_trans);
return 0;
- }
- /* parent */
- trans_delete(server_trans);
- return 0;
}
/*****************************************************************************/
/* a new connection is coming in */
int DEFAULT_CC
-xrdp_listen_conn_in(struct trans* self, struct trans* new_self)
+xrdp_listen_conn_in(struct trans *self, struct trans *new_self)
{
- struct xrdp_process* process;
- struct xrdp_listen* lis;
-
- lis = (struct xrdp_listen*)(self->callback_data);
- if (lis->startup_params->fork)
- {
- return xrdp_listen_fork(lis, new_self);
- }
- process = xrdp_process_create(lis, lis->pro_done_event);
- if (xrdp_listen_add_pro(lis, process) == 0)
- {
- /* start thread */
- process->server_trans = new_self;
- g_process = process;
- tc_thread_create(xrdp_process_run, 0);
- tc_sem_dec(g_process_sem); /* this will wait */
- }
- else
- {
- xrdp_process_delete(process);
- }
- return 0;
+ struct xrdp_process *process;
+ struct xrdp_listen *lis;
+
+ lis = (struct xrdp_listen *)(self->callback_data);
+
+ if (lis->startup_params->fork)
+ {
+ return xrdp_listen_fork(lis, new_self);
+ }
+
+ process = xrdp_process_create(lis, lis->pro_done_event);
+
+ if (xrdp_listen_add_pro(lis, process) == 0)
+ {
+ /* start thread */
+ process->server_trans = new_self;
+ g_process = process;
+ tc_thread_create(xrdp_process_run, 0);
+ tc_sem_dec(g_process_sem); /* this will wait */
+ }
+ else
+ {
+ xrdp_process_delete(process);
+ }
+
+ return 0;
}
/*****************************************************************************/
/* wait for incoming connections */
int APP_CC
-xrdp_listen_main_loop(struct xrdp_listen* self)
+xrdp_listen_main_loop(struct xrdp_listen *self)
{
- int error;
- int robjs_count;
- int cont;
- int timeout = 0;
- char port[128];
- char address[256];
- tbus robjs[8];
- tbus term_obj;
- tbus sync_obj;
- tbus done_obj;
- int tcp_nodelay;
- int tcp_keepalive;
-
- self->status = 1;
- if (xrdp_listen_get_port_address(port, sizeof(port),
- address, sizeof(address),
- &tcp_nodelay, &tcp_keepalive,
- self->startup_params) != 0)
- {
- g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed");
- self->status = -1;
- return 1;
- }
- /*Create socket*/
- error = trans_listen_address(self->listen_trans, port, address);
- if (error == 0)
- {
- if(tcp_nodelay)
- {
- if(g_tcp_set_no_delay(self->listen_trans->sck))
- {
- g_writeln("Error setting tcp_nodelay");
- }
- }
- if(tcp_keepalive)
+ int error;
+ int robjs_count;
+ int cont;
+ int timeout = 0;
+ char port[128];
+ char address[256];
+ tbus robjs[8];
+ tbus term_obj;
+ tbus sync_obj;
+ tbus done_obj;
+ int tcp_nodelay;
+ int tcp_keepalive;
+
+ self->status = 1;
+
+ if (xrdp_listen_get_port_address(port, sizeof(port),
+ address, sizeof(address),
+ &tcp_nodelay, &tcp_keepalive,
+ self->startup_params) != 0)
{
- if(g_tcp_set_keepalive(self->listen_trans->sck))
- {
- g_writeln("Error setting tcp_keepalive");
- }
+ g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed");
+ self->status = -1;
+ return 1;
}
- self->listen_trans->trans_conn_in = xrdp_listen_conn_in;
- self->listen_trans->callback_data = self;
- term_obj = g_get_term_event(); /*Global termination event */
- sync_obj = g_get_sync_event();
- done_obj = self->pro_done_event;
- cont = 1;
- while (cont)
+
+ /*Create socket*/
+ error = trans_listen_address(self->listen_trans, port, address);
+
+ if (error == 0)
{
- /* build the wait obj list */
- robjs_count = 0;
- robjs[robjs_count++] = term_obj;
- robjs[robjs_count++] = sync_obj;
- robjs[robjs_count++] = done_obj;
- timeout = -1;
- if (trans_get_wait_objs(self->listen_trans, robjs, &robjs_count) != 0)
- {
- g_writeln("Listening socket is in wrong state we terminate listener") ;
- break;
- }
- /* wait - timeout -1 means wait indefinitely*/
- if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0)
- {
- /* error, should not get here */
- g_sleep(100);
- }
- if (g_is_wait_obj_set(term_obj)) /* termination called */
- {
- break;
- }
- if (g_is_wait_obj_set(sync_obj)) /* some function must be processed by this thread */
- {
- g_reset_wait_obj(sync_obj);
- g_process_waiting_function(); /* run the function */
- }
- if (g_is_wait_obj_set(done_obj)) /* pro_done_event */
- {
- g_reset_wait_obj(done_obj);
- /* a process has died remove it from lists*/
- xrdp_listen_delete_done_pro(self);
- }
- /* Run the callback when accept() returns a new socket*/
- if (trans_check_wait_objs(self->listen_trans) != 0)
- {
- break;
- }
+ if (tcp_nodelay)
+ {
+ if (g_tcp_set_no_delay(self->listen_trans->sck))
+ {
+ g_writeln("Error setting tcp_nodelay");
+ }
+ }
+
+ if (tcp_keepalive)
+ {
+ if (g_tcp_set_keepalive(self->listen_trans->sck))
+ {
+ g_writeln("Error setting tcp_keepalive");
+ }
+ }
+
+ self->listen_trans->trans_conn_in = xrdp_listen_conn_in;
+ self->listen_trans->callback_data = self;
+ term_obj = g_get_term_event(); /*Global termination event */
+ sync_obj = g_get_sync_event();
+ done_obj = self->pro_done_event;
+ cont = 1;
+
+ while (cont)
+ {
+ /* build the wait obj list */
+ robjs_count = 0;
+ robjs[robjs_count++] = term_obj;
+ robjs[robjs_count++] = sync_obj;
+ robjs[robjs_count++] = done_obj;
+ timeout = -1;
+
+ if (trans_get_wait_objs(self->listen_trans, robjs, &robjs_count) != 0)
+ {
+ g_writeln("Listening socket is in wrong state we terminate listener") ;
+ break;
+ }
+
+ /* wait - timeout -1 means wait indefinitely*/
+ if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0)
+ {
+ /* error, should not get here */
+ g_sleep(100);
+ }
+
+ if (g_is_wait_obj_set(term_obj)) /* termination called */
+ {
+ break;
+ }
+
+ if (g_is_wait_obj_set(sync_obj)) /* some function must be processed by this thread */
+ {
+ g_reset_wait_obj(sync_obj);
+ g_process_waiting_function(); /* run the function */
+ }
+
+ if (g_is_wait_obj_set(done_obj)) /* pro_done_event */
+ {
+ g_reset_wait_obj(done_obj);
+ /* a process has died remove it from lists*/
+ xrdp_listen_delete_done_pro(self);
+ }
+
+ /* Run the callback when accept() returns a new socket*/
+ if (trans_check_wait_objs(self->listen_trans) != 0)
+ {
+ break;
+ }
+ }
+
+ /* stop listening */
+ trans_delete(self->listen_trans);
+ self->listen_trans = 0;
+ /* second loop to wait for all process threads to close */
+ cont = 1;
+
+ while (cont)
+ {
+ if (self->process_list->count == 0)
+ {
+ break;
+ }
+
+ timeout = -1;
+ /* build the wait obj list */
+ robjs_count = 0;
+ robjs[robjs_count++] = sync_obj;
+ robjs[robjs_count++] = done_obj;
+
+ /* wait - timeout -1 means wait indefinitely*/
+ if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0)
+ {
+ /* error, should not get here */
+ g_sleep(100);
+ }
+
+ if (g_is_wait_obj_set(sync_obj)) /* some function must be processed by this thread */
+ {
+ g_reset_wait_obj(sync_obj);
+ g_process_waiting_function(); /* run the function that is waiting*/
+ }
+
+ if (g_is_wait_obj_set(done_obj)) /* pro_done_event */
+ {
+ g_reset_wait_obj(done_obj);
+ xrdp_listen_delete_done_pro(self);
+ }
+ }
}
- /* stop listening */
- trans_delete(self->listen_trans);
- self->listen_trans = 0;
- /* second loop to wait for all process threads to close */
- cont = 1;
- while (cont)
+ else
{
- if (self->process_list->count == 0)
- {
- break;
- }
- timeout = -1;
- /* build the wait obj list */
- robjs_count = 0;
- robjs[robjs_count++] = sync_obj;
- robjs[robjs_count++] = done_obj;
- /* wait - timeout -1 means wait indefinitely*/
- if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0)
- {
- /* error, should not get here */
- g_sleep(100);
- }
- if (g_is_wait_obj_set(sync_obj)) /* some function must be processed by this thread */
- {
- g_reset_wait_obj(sync_obj);
- g_process_waiting_function(); /* run the function that is waiting*/
- }
- if (g_is_wait_obj_set(done_obj)) /* pro_done_event */
- {
- g_reset_wait_obj(done_obj);
- xrdp_listen_delete_done_pro(self);
- }
+ g_writeln("xrdp_listen_main_loop: listen error, possible port "
+ "already in use");
}
- }
- else
- {
- g_writeln("xrdp_listen_main_loop: listen error, possible port "
- "already in use");
- }
- self->status = -1;
- return 0;
+
+ self->status = -1;
+ return 0;
}
diff --git a/xrdp/xrdp_login_wnd.c b/xrdp/xrdp_login_wnd.c
index 69d3721f..fc4cf125 100644
--- a/xrdp/xrdp_login_wnd.c
+++ b/xrdp/xrdp_login_wnd.c
@@ -1,24 +1,22 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- main login window and login help window
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * main login window and login help window
+ */
#include "xrdp.h"
#define ACCESS
@@ -27,571 +25,616 @@
/*****************************************************************************/
/* all login help screen events go here */
static int DEFAULT_CC
-xrdp_wm_login_help_notify(struct xrdp_bitmap* wnd,
- struct xrdp_bitmap* sender,
+xrdp_wm_login_help_notify(struct xrdp_bitmap *wnd,
+ struct xrdp_bitmap *sender,
int msg, long param1, long param2)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
- if (wnd == 0)
- {
- return 0;
- }
- if (sender == 0)
- {
- return 0;
- }
- if (wnd->owner == 0)
- {
- return 0;
- }
- if (msg == 1) /* click */
- {
- if (sender->id == 1) /* ok button */
+ if (wnd == 0)
{
- if (sender->owner->notify != 0)
- {
- wnd->owner->notify(wnd->owner, wnd, 100, 1, 0); /* ok */
- }
+ return 0;
+ }
+
+ if (sender == 0)
+ {
+ return 0;
+ }
+
+ if (wnd->owner == 0)
+ {
+ return 0;
+ }
+
+ if (msg == 1) /* click */
+ {
+ if (sender->id == 1) /* ok button */
+ {
+ if (sender->owner->notify != 0)
+ {
+ wnd->owner->notify(wnd->owner, wnd, 100, 1, 0); /* ok */
+ }
+ }
}
- }
- else if (msg == WM_PAINT) /* 3 */
- {
- p = (struct xrdp_painter*)param1;
- if (p != 0)
+ else if (msg == WM_PAINT) /* 3 */
{
- p->fg_color = wnd->wm->black;
- xrdp_painter_draw_text(p, wnd, 10, 30, "You must be authenticated \
+ p = (struct xrdp_painter *)param1;
+
+ if (p != 0)
+ {
+ p->fg_color = wnd->wm->black;
+ xrdp_painter_draw_text(p, wnd, 10, 30, "You must be authenticated \
before using this");
- xrdp_painter_draw_text(p, wnd, 10, 46, "session.");
- xrdp_painter_draw_text(p, wnd, 10, 78, "Enter a valid username in \
+ xrdp_painter_draw_text(p, wnd, 10, 46, "session.");
+ xrdp_painter_draw_text(p, wnd, 10, 78, "Enter a valid username in \
the username edit box.");
- xrdp_painter_draw_text(p, wnd, 10, 94, "Enter the password in \
+ xrdp_painter_draw_text(p, wnd, 10, 94, "Enter the password in \
the password edit box.");
- xrdp_painter_draw_text(p, wnd, 10, 110, "Both the username and \
+ xrdp_painter_draw_text(p, wnd, 10, 110, "Both the username and \
password are case");
- xrdp_painter_draw_text(p, wnd, 10, 126, "sensitive.");
- xrdp_painter_draw_text(p, wnd, 10, 158, "Contact your system \
+ xrdp_painter_draw_text(p, wnd, 10, 126, "sensitive.");
+ xrdp_painter_draw_text(p, wnd, 10, 158, "Contact your system \
administrator if you are");
- xrdp_painter_draw_text(p, wnd, 10, 174, "having problems \
+ xrdp_painter_draw_text(p, wnd, 10, 174, "having problems \
logging on.");
+ }
}
- }
- return 0;
+
+ return 0;
}
#if 0
/*****************************************************************************/
static int DEFAULT_CC
-xrdp_wm_popup_notify(struct xrdp_bitmap* wnd,
- struct xrdp_bitmap* sender,
+xrdp_wm_popup_notify(struct xrdp_bitmap *wnd,
+ struct xrdp_bitmap *sender,
int msg, int param1, int param2)
{
- return 0;
+ return 0;
}
#endif
/*****************************************************************************/
int APP_CC
-xrdp_wm_delete_all_childs(struct xrdp_wm* self)
+xrdp_wm_delete_all_childs(struct xrdp_wm *self)
{
- int index;
- struct xrdp_bitmap* b;
- struct xrdp_rect rect;
-
- for (index = self->screen->child_list->count - 1; index >= 0; index--)
- {
- b = (struct xrdp_bitmap*)list_get_item(self->screen->child_list, index);
- MAKERECT(rect, b->left, b->top, b->width, b->height);
- xrdp_bitmap_delete(b);
- xrdp_bitmap_invalidate(self->screen, &rect);
- }
- return 0;
+ int index;
+ struct xrdp_bitmap *b;
+ struct xrdp_rect rect;
+
+ for (index = self->screen->child_list->count - 1; index >= 0; index--)
+ {
+ b = (struct xrdp_bitmap *)list_get_item(self->screen->child_list, index);
+ MAKERECT(rect, b->left, b->top, b->width, b->height);
+ xrdp_bitmap_delete(b);
+ xrdp_bitmap_invalidate(self->screen, &rect);
+ }
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-set_mod_data_item(struct xrdp_mod_data* mod, char* name, char* value)
+set_mod_data_item(struct xrdp_mod_data *mod, char *name, char *value)
{
- int index;
+ int index;
- for (index = 0; index < mod->names->count; index++)
- {
- if (g_strncmp(name, (char*)list_get_item(mod->names, index), 255) == 0)
+ for (index = 0; index < mod->names->count; index++)
{
- list_remove_item(mod->values, index);
- list_insert_item(mod->values, index, (long)g_strdup(value));
+ if (g_strncmp(name, (char *)list_get_item(mod->names, index), 255) == 0)
+ {
+ list_remove_item(mod->values, index);
+ list_insert_item(mod->values, index, (long)g_strdup(value));
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_help_clicked(struct xrdp_bitmap* wnd)
+xrdp_wm_help_clicked(struct xrdp_bitmap *wnd)
{
- struct xrdp_bitmap* help;
- struct xrdp_bitmap* but;
-
- /* create help screen */
- help = xrdp_bitmap_create(DEFAULT_WND_HELP_W, DEFAULT_WND_HELP_H, wnd->wm->screen->bpp,
- WND_TYPE_WND, wnd->wm);
- list_insert_item(wnd->wm->screen->child_list, 0, (long)help);
- help->parent = wnd->wm->screen;
- help->owner = wnd;
- wnd->modal_dialog = help;
- help->bg_color = wnd->wm->grey;
- help->left = wnd->wm->screen->width / 2 - help->width / 2;
- help->top = wnd->wm->screen->height / 2 - help->height / 2;
- help->notify = xrdp_wm_login_help_notify;
- set_string(&help->caption1, "Login help");
- /* ok button */
- but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, wnd->wm->screen->bpp,
- WND_TYPE_BUTTON, wnd->wm);
- list_insert_item(help->child_list, 0, (long)but);
- but->parent = help;
- but->owner = help;
- but->left = ((DEFAULT_WND_HELP_W / 2) - (DEFAULT_BUTTON_W / 2)); /* center */
- but->top = DEFAULT_WND_HELP_H - DEFAULT_BUTTON_H - 15;
- but->id = 1;
- but->tab_stop = 1;
- set_string(&but->caption1, "OK");
- /* draw it */
- help->focused_control = but;
- help->default_button = but;
- help->esc_button = but;
- xrdp_bitmap_invalidate(help, 0);
- xrdp_wm_set_focused(wnd->wm, help);
- return 0;
+ struct xrdp_bitmap *help;
+ struct xrdp_bitmap *but;
+
+ /* create help screen */
+ help = xrdp_bitmap_create(DEFAULT_WND_HELP_W, DEFAULT_WND_HELP_H, wnd->wm->screen->bpp,
+ WND_TYPE_WND, wnd->wm);
+ list_insert_item(wnd->wm->screen->child_list, 0, (long)help);
+ help->parent = wnd->wm->screen;
+ help->owner = wnd;
+ wnd->modal_dialog = help;
+ help->bg_color = wnd->wm->grey;
+ help->left = wnd->wm->screen->width / 2 - help->width / 2;
+ help->top = wnd->wm->screen->height / 2 - help->height / 2;
+ help->notify = xrdp_wm_login_help_notify;
+ set_string(&help->caption1, "Login help");
+ /* ok button */
+ but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, wnd->wm->screen->bpp,
+ WND_TYPE_BUTTON, wnd->wm);
+ list_insert_item(help->child_list, 0, (long)but);
+ but->parent = help;
+ but->owner = help;
+ but->left = ((DEFAULT_WND_HELP_W / 2) - (DEFAULT_BUTTON_W / 2)); /* center */
+ but->top = DEFAULT_WND_HELP_H - DEFAULT_BUTTON_H - 15;
+ but->id = 1;
+ but->tab_stop = 1;
+ set_string(&but->caption1, "OK");
+ /* draw it */
+ help->focused_control = but;
+ help->default_button = but;
+ help->esc_button = but;
+ xrdp_bitmap_invalidate(help, 0);
+ xrdp_wm_set_focused(wnd->wm, help);
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_cancel_clicked(struct xrdp_bitmap* wnd)
+xrdp_wm_cancel_clicked(struct xrdp_bitmap *wnd)
{
- if (wnd != 0)
- {
- if (wnd->wm != 0)
+ if (wnd != 0)
{
- if (wnd->wm->pro_layer != 0)
- {
- g_set_wait_obj(wnd->wm->pro_layer->self_term_event);
- }
+ if (wnd->wm != 0)
+ {
+ if (wnd->wm->pro_layer != 0)
+ {
+ g_set_wait_obj(wnd->wm->pro_layer->self_term_event);
+ }
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_ok_clicked(struct xrdp_bitmap* wnd)
+xrdp_wm_ok_clicked(struct xrdp_bitmap *wnd)
{
- struct xrdp_bitmap* combo;
- struct xrdp_bitmap* label;
- struct xrdp_bitmap* edit;
- struct xrdp_wm* wm;
- struct xrdp_mod_data* mod_data;
- int i;
-
- wm = wnd->wm;
- combo = xrdp_bitmap_get_child_by_id(wnd, 6);
- if (combo != 0)
- {
- mod_data = (struct xrdp_mod_data*)
- list_get_item(combo->data_list, combo->item_index);
- if (mod_data != 0)
+ struct xrdp_bitmap *combo;
+ struct xrdp_bitmap *label;
+ struct xrdp_bitmap *edit;
+ struct xrdp_wm *wm;
+ struct xrdp_mod_data *mod_data;
+ int i;
+
+ wm = wnd->wm;
+ combo = xrdp_bitmap_get_child_by_id(wnd, 6);
+
+ if (combo != 0)
{
- /* get the user typed values */
- i = 100;
- label = xrdp_bitmap_get_child_by_id(wnd, i);
- edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);
- while (label != 0 && edit != 0)
- {
- set_mod_data_item(mod_data, label->caption1, edit->caption1);
- i += 2;
- label = xrdp_bitmap_get_child_by_id(wnd, i);
- edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);
- }
- 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);
- xrdp_wm_set_login_mode(wm, 2);
+ mod_data = (struct xrdp_mod_data *)
+ list_get_item(combo->data_list, combo->item_index);
+
+ if (mod_data != 0)
+ {
+ /* get the user typed values */
+ i = 100;
+ label = xrdp_bitmap_get_child_by_id(wnd, i);
+ edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);
+
+ while (label != 0 && edit != 0)
+ {
+ set_mod_data_item(mod_data, label->caption1, edit->caption1);
+ i += 2;
+ label = xrdp_bitmap_get_child_by_id(wnd, i);
+ edit = xrdp_bitmap_get_child_by_id(wnd, i + 1);
+ }
+
+ 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);
+ xrdp_wm_set_login_mode(wm, 2);
+ }
}
- }
- else
- {
- log_message(LOG_LEVEL_ERROR,"Combo is 0 - potential programming error");
- }
- return 0;
+ else
+ {
+ log_message(LOG_LEVEL_ERROR, "Combo is 0 - potential programming error");
+ }
+
+ return 0;
}
/******************************************************************************/
static int APP_CC
-xrdp_wm_show_edits(struct xrdp_wm* self, struct xrdp_bitmap* combo)
+xrdp_wm_show_edits(struct xrdp_wm *self, struct xrdp_bitmap *combo)
{
- int count;
- int index;
- int insert_index;
- int username_set;
- char* name;
- char* value;
- struct xrdp_mod_data* mod;
- struct xrdp_bitmap* b;
-
- username_set = 0;
- /* free labels and edits, cause we gota create them */
- /* creation or combo changed */
- for (index = 100; index < 200; index++)
- {
- b = xrdp_bitmap_get_child_by_id(combo->parent, index);
- xrdp_bitmap_delete(b);
- }
-
- insert_index = list_index_of(self->login_window->child_list,
- (long)combo);
- insert_index++;
- mod = (struct xrdp_mod_data*)
- list_get_item(combo->data_list, combo->item_index);
- if (mod != 0)
- {
- count = 0;
- for (index = 0; index < mod->names->count; index++)
+ int count;
+ int index;
+ int insert_index;
+ int username_set;
+ char *name;
+ char *value;
+ struct xrdp_mod_data *mod;
+ struct xrdp_bitmap *b;
+
+ username_set = 0;
+
+ /* free labels and edits, cause we gota create them */
+ /* creation or combo changed */
+ for (index = 100; index < 200; index++)
{
- value = (char*)list_get_item(mod->values, index);
- if (g_strncmp("ask", value, 3) == 0)
- {
- /* label */
- b = xrdp_bitmap_create(95, DEFAULT_EDIT_H, self->screen->bpp,
- WND_TYPE_LABEL, self);
- list_insert_item(self->login_window->child_list, insert_index,
- (long)b);
- insert_index++;
- b->parent = self->login_window;
- b->owner = self->login_window;
- b->left = self->login_window->width >= DEFAULT_WND_LOGIN_W ? 155 : 5;
- b->top = DEFAULT_ELEMENT_TOP + DEFAULT_COMBO_H + 5 + (DEFAULT_EDIT_H+5) * count;
- b->id = 100 + 2 * count;
- name = (char*)list_get_item(mod->names, index);
- set_string(&b->caption1, name);
- /* edit */
- b = xrdp_bitmap_create(DEFAULT_EDIT_W, DEFAULT_EDIT_H, self->screen->bpp,
- WND_TYPE_EDIT, self);
- list_insert_item(self->login_window->child_list, insert_index,
- (long)b);
- insert_index++;
- b->parent = self->login_window;
- b->owner = self->login_window;
- b->left = self->login_window->width >= DEFAULT_WND_LOGIN_W ? DEFAULT_WND_LOGIN_W - DEFAULT_EDIT_W - 30 : 70;
- b->top = DEFAULT_ELEMENT_TOP + DEFAULT_COMBO_H + 5 + (DEFAULT_EDIT_H+5) * count;
- b->id = 100 + 2 * count + 1;
- b->pointer = 1;
- b->tab_stop = 1;
- b->caption1 = (char*)g_malloc(256, 1);
- g_strncpy(b->caption1, value + 3, 255);
- b->edit_pos = g_mbstowcs(0, b->caption1, 0);
- if (self->login_window->focused_control == 0)
- {
- self->login_window->focused_control = b;
- }
- if (g_strncmp(name, "username", 255) == 0)
- {
- g_strncpy(b->caption1, self->session->client_info->username, 255);
- b->edit_pos = g_mbstowcs(0, b->caption1, 0);
- if (b->edit_pos > 0)
- {
- username_set = 1;
- }
- }
-#ifdef ACCESS
- if ((g_strncmp(name, "password", 255) == 0) || (g_strncmp(name, "pampassword", 255) == 0))
-#else
- if (g_strncmp(name, "password", 255) == 0)
-#endif
+ b = xrdp_bitmap_get_child_by_id(combo->parent, index);
+ xrdp_bitmap_delete(b);
+ }
+
+ insert_index = list_index_of(self->login_window->child_list,
+ (long)combo);
+ insert_index++;
+ mod = (struct xrdp_mod_data *)
+ list_get_item(combo->data_list, combo->item_index);
+
+ if (mod != 0)
+ {
+ count = 0;
+
+ for (index = 0; index < mod->names->count; index++)
{
- b->password_char = '*';
- if (username_set)
- {
- if (b->parent != 0)
+ value = (char *)list_get_item(mod->values, index);
+
+ if (g_strncmp("ask", value, 3) == 0)
{
- b->parent->focused_control = b;
+ /* label */
+ b = xrdp_bitmap_create(95, DEFAULT_EDIT_H, self->screen->bpp,
+ WND_TYPE_LABEL, self);
+ list_insert_item(self->login_window->child_list, insert_index,
+ (long)b);
+ insert_index++;
+ b->parent = self->login_window;
+ b->owner = self->login_window;
+ b->left = self->login_window->width >= DEFAULT_WND_LOGIN_W ? 155 : 5;
+ b->top = DEFAULT_ELEMENT_TOP + DEFAULT_COMBO_H + 5 + (DEFAULT_EDIT_H + 5) * count;
+ b->id = 100 + 2 * count;
+ name = (char *)list_get_item(mod->names, index);
+ set_string(&b->caption1, name);
+ /* edit */
+ b = xrdp_bitmap_create(DEFAULT_EDIT_W, DEFAULT_EDIT_H, self->screen->bpp,
+ WND_TYPE_EDIT, self);
+ list_insert_item(self->login_window->child_list, insert_index,
+ (long)b);
+ insert_index++;
+ b->parent = self->login_window;
+ b->owner = self->login_window;
+ b->left = self->login_window->width >= DEFAULT_WND_LOGIN_W ? DEFAULT_WND_LOGIN_W - DEFAULT_EDIT_W - 30 : 70;
+ b->top = DEFAULT_ELEMENT_TOP + DEFAULT_COMBO_H + 5 + (DEFAULT_EDIT_H + 5) * count;
+ b->id = 100 + 2 * count + 1;
+ b->pointer = 1;
+ b->tab_stop = 1;
+ b->caption1 = (char *)g_malloc(256, 1);
+ g_strncpy(b->caption1, value + 3, 255);
+ b->edit_pos = g_mbstowcs(0, b->caption1, 0);
+
+ if (self->login_window->focused_control == 0)
+ {
+ self->login_window->focused_control = b;
+ }
+
+ if (g_strncmp(name, "username", 255) == 0)
+ {
+ g_strncpy(b->caption1, self->session->client_info->username, 255);
+ b->edit_pos = g_mbstowcs(0, b->caption1, 0);
+
+ if (b->edit_pos > 0)
+ {
+ username_set = 1;
+ }
+ }
+
+#ifdef ACCESS
+
+ if ((g_strncmp(name, "password", 255) == 0) || (g_strncmp(name, "pampassword", 255) == 0))
+#else
+ if (g_strncmp(name, "password", 255) == 0)
+#endif
+ {
+ b->password_char = '*';
+
+ if (username_set)
+ {
+ if (b->parent != 0)
+ {
+ b->parent->focused_control = b;
+ }
+ }
+ }
+
+ count++;
}
- }
}
- count++;
- }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* all login screen events go here */
static int DEFAULT_CC
-xrdp_wm_login_notify(struct xrdp_bitmap* wnd,
- struct xrdp_bitmap* sender,
+xrdp_wm_login_notify(struct xrdp_bitmap *wnd,
+ struct xrdp_bitmap *sender,
int msg, long param1, long param2)
{
- struct xrdp_bitmap* b;
- struct xrdp_rect rect;
- int i;
+ struct xrdp_bitmap *b;
+ struct xrdp_rect rect;
+ int i;
- if (wnd->modal_dialog != 0 && msg != 100)
- {
- return 0;
- }
- if (msg == 1) /* click */
- {
- if (sender->id == 1) /* help button */
+ if (wnd->modal_dialog != 0 && msg != 100)
{
- xrdp_wm_help_clicked(wnd);
+ return 0;
}
- else if (sender->id == 2) /* cancel button */
+
+ if (msg == 1) /* click */
{
- xrdp_wm_cancel_clicked(wnd);
+ if (sender->id == 1) /* help button */
+ {
+ xrdp_wm_help_clicked(wnd);
+ }
+ else if (sender->id == 2) /* cancel button */
+ {
+ xrdp_wm_cancel_clicked(wnd);
+ }
+ else if (sender->id == 3) /* ok button */
+ {
+ xrdp_wm_ok_clicked(wnd);
+ }
}
- else if (sender->id == 3) /* ok button */
+ else if (msg == 2) /* mouse move */
{
- xrdp_wm_ok_clicked(wnd);
}
- }
- else if (msg == 2) /* mouse move */
- {
- }
- else if (msg == 100) /* modal result is done */
- {
- i = list_index_of(wnd->wm->screen->child_list, (long)sender);
- if (i >= 0)
+ else if (msg == 100) /* modal result is done */
{
- b = (struct xrdp_bitmap*)
- list_get_item(wnd->wm->screen->child_list, i);
- list_remove_item(sender->wm->screen->child_list, i);
- MAKERECT(rect, b->left, b->top, b->width, b->height);
- xrdp_bitmap_invalidate(wnd->wm->screen, &rect);
- xrdp_bitmap_delete(sender);
- wnd->modal_dialog = 0;
- xrdp_wm_set_focused(wnd->wm, wnd);
+ i = list_index_of(wnd->wm->screen->child_list, (long)sender);
+
+ if (i >= 0)
+ {
+ b = (struct xrdp_bitmap *)
+ list_get_item(wnd->wm->screen->child_list, i);
+ list_remove_item(sender->wm->screen->child_list, i);
+ MAKERECT(rect, b->left, b->top, b->width, b->height);
+ xrdp_bitmap_invalidate(wnd->wm->screen, &rect);
+ xrdp_bitmap_delete(sender);
+ wnd->modal_dialog = 0;
+ xrdp_wm_set_focused(wnd->wm, wnd);
+ }
}
- }
- else if (msg == CB_ITEMCHANGE) /* combo box change */
- {
- xrdp_wm_show_edits(wnd->wm, sender);
- xrdp_bitmap_invalidate(wnd, 0); /* invalidate the whole dialog for now */
- }
- return 0;
+ else if (msg == CB_ITEMCHANGE) /* combo box change */
+ {
+ xrdp_wm_show_edits(wnd->wm, sender);
+ xrdp_bitmap_invalidate(wnd, 0); /* invalidate the whole dialog for now */
+ }
+
+ return 0;
}
/******************************************************************************/
static int APP_CC
-xrdp_wm_login_fill_in_combo(struct xrdp_wm* self, struct xrdp_bitmap* b)
+xrdp_wm_login_fill_in_combo(struct xrdp_wm *self, struct xrdp_bitmap *b)
{
- struct list* sections;
- struct list* section_names;
- struct list* section_values;
- int fd;
- int i;
- int j;
- char* p;
- char* q;
- char* r;
- char name[256];
- char cfg_file[256];
- struct xrdp_mod_data* mod_data;
-
- sections = list_create();
- sections->auto_free = 1;
- section_names = list_create();
- section_names->auto_free = 1;
- section_values = list_create();
- section_values->auto_free = 1;
- g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
- fd = g_file_open(cfg_file); /* xrdp.ini */
- if (fd < 1)
- {
- log_message(LOG_LEVEL_ERROR,"Could not read xrdp ini file %s", cfg_file);
- }
- file_read_sections(fd, sections);
- for (i = 0; i < sections->count; i++)
- {
- p = (char*)list_get_item(sections, i);
- file_read_section(fd, p, section_names, section_values);
- if ((g_strncmp(p, "globals", 255) == 0)
- ||(g_strncmp(p, "channels", 255) == 0)
- ||(g_strncmp(p, "Logging", 255) == 0))
+ struct list *sections;
+ struct list *section_names;
+ struct list *section_values;
+ int fd;
+ int i;
+ int j;
+ char *p;
+ char *q;
+ char *r;
+ char name[256];
+ char cfg_file[256];
+ struct xrdp_mod_data *mod_data;
+
+ sections = list_create();
+ sections->auto_free = 1;
+ section_names = list_create();
+ section_names->auto_free = 1;
+ section_values = list_create();
+ section_values->auto_free = 1;
+ g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+ fd = g_file_open(cfg_file); /* xrdp.ini */
+
+ if (fd < 1)
{
+ log_message(LOG_LEVEL_ERROR, "Could not read xrdp ini file %s", cfg_file);
}
- else
+
+ file_read_sections(fd, sections);
+
+ for (i = 0; i < sections->count; i++)
{
- g_strncpy(name, p, 255);
- mod_data = (struct xrdp_mod_data*)
- g_malloc(sizeof(struct xrdp_mod_data), 1);
- mod_data->names = list_create();
- mod_data->names->auto_free = 1;
- mod_data->values = list_create();
- mod_data->values->auto_free = 1;
- for (j = 0; j < section_names->count; j++)
- {
- q = (char*)list_get_item(section_names, j);
- r = (char*)list_get_item(section_values, j);
- if (g_strncmp("name", q, 255) == 0)
+ p = (char *)list_get_item(sections, i);
+ file_read_section(fd, p, section_names, section_values);
+
+ if ((g_strncmp(p, "globals", 255) == 0)
+ || (g_strncmp(p, "channels", 255) == 0)
+ || (g_strncmp(p, "Logging", 255) == 0))
{
- g_strncpy(name, r, 255);
}
- list_add_item(mod_data->names, (long)g_strdup(q));
- list_add_item(mod_data->values, (long)g_strdup(r));
- }
- list_add_item(b->string_list, (long)g_strdup(name));
- list_add_item(b->data_list, (long)mod_data);
+ else
+ {
+ g_strncpy(name, p, 255);
+ mod_data = (struct xrdp_mod_data *)
+ g_malloc(sizeof(struct xrdp_mod_data), 1);
+ mod_data->names = list_create();
+ mod_data->names->auto_free = 1;
+ mod_data->values = list_create();
+ mod_data->values->auto_free = 1;
+
+ for (j = 0; j < section_names->count; j++)
+ {
+ q = (char *)list_get_item(section_names, j);
+ r = (char *)list_get_item(section_values, j);
+
+ if (g_strncmp("name", q, 255) == 0)
+ {
+ g_strncpy(name, r, 255);
+ }
+
+ list_add_item(mod_data->names, (long)g_strdup(q));
+ list_add_item(mod_data->values, (long)g_strdup(r));
+ }
+
+ list_add_item(b->string_list, (long)g_strdup(name));
+ list_add_item(b->data_list, (long)mod_data);
+ }
}
- }
- g_file_close(fd);
- list_delete(sections);
- list_delete(section_names);
- list_delete(section_values);
- return 0;
+
+ g_file_close(fd);
+ list_delete(sections);
+ list_delete(section_names);
+ list_delete(section_values);
+ return 0;
}
/******************************************************************************/
int APP_CC
-xrdp_login_wnd_create(struct xrdp_wm* self)
+xrdp_login_wnd_create(struct xrdp_wm *self)
{
- struct xrdp_bitmap* but;
- struct xrdp_bitmap* combo;
- char file_path[256];
- int log_width;
- int log_height;
- int regular;
-
- log_width = DEFAULT_WND_LOGIN_W;
- log_height = DEFAULT_WND_LOGIN_H;
- regular = 1;
- if (self->screen->width < log_width)
- {
- if (self->screen->width < 240)
- {
- log_width = self->screen->width - 4;
- }
- else
- {
- log_width = 240;
- }
- regular = 0;
- }
- /* draw login window */
- self->login_window = xrdp_bitmap_create(log_width, log_height, self->screen->bpp,
- WND_TYPE_WND, self);
- list_add_item(self->screen->child_list, (long)self->login_window);
- self->login_window->parent = self->screen;
- self->login_window->owner = self->screen;
- self->login_window->bg_color = self->grey;
- self->login_window->left = self->screen->width / 2 -
- self->login_window->width / 2;
- self->login_window->top = self->screen->height / 2 -
- self->login_window->height / 2;
- self->login_window->notify = xrdp_wm_login_notify;
- set_string(&self->login_window->caption1, "Login to xrdp");
- if (regular)
- {
- /* image */
- but = xrdp_bitmap_create(4, 4, self->screen->bpp, WND_TYPE_IMAGE, self);
- if (self->screen->bpp > 8)
- {
- g_snprintf(file_path, 255, "%s/xrdp24b.bmp", XRDP_SHARE_PATH);
- }
- else
+ struct xrdp_bitmap *but;
+ struct xrdp_bitmap *combo;
+ char file_path[256];
+ int log_width;
+ int log_height;
+ int regular;
+
+ log_width = DEFAULT_WND_LOGIN_W;
+ log_height = DEFAULT_WND_LOGIN_H;
+ regular = 1;
+
+ if (self->screen->width < log_width)
{
- g_snprintf(file_path, 255, "%s/xrdp256.bmp", XRDP_SHARE_PATH);
- }
- xrdp_bitmap_load(but, file_path, self->palette);
- but->parent = self->screen;
- but->owner = self->screen;
- but->left = self->screen->width - but->width;
- but->top = self->screen->height - but->height;
- list_add_item(self->screen->child_list, (long)but);
-
- /* image */
- but = xrdp_bitmap_create(4, 4, self->screen->bpp, WND_TYPE_IMAGE, self);
- if (self->screen->bpp > 8)
- {
- g_snprintf(file_path, 255, "%s/ad24b.bmp", XRDP_SHARE_PATH);
+ if (self->screen->width < 240)
+ {
+ log_width = self->screen->width - 4;
+ }
+ else
+ {
+ log_width = 240;
+ }
+
+ regular = 0;
}
- else
+
+ /* draw login window */
+ self->login_window = xrdp_bitmap_create(log_width, log_height, self->screen->bpp,
+ WND_TYPE_WND, self);
+ list_add_item(self->screen->child_list, (long)self->login_window);
+ self->login_window->parent = self->screen;
+ self->login_window->owner = self->screen;
+ self->login_window->bg_color = self->grey;
+ self->login_window->left = self->screen->width / 2 -
+ self->login_window->width / 2;
+ self->login_window->top = self->screen->height / 2 -
+ self->login_window->height / 2;
+ self->login_window->notify = xrdp_wm_login_notify;
+ set_string(&self->login_window->caption1, "Login to xrdp");
+
+ if (regular)
{
- g_snprintf(file_path, 255, "%s/ad256.bmp", XRDP_SHARE_PATH);
+ /* image */
+ but = xrdp_bitmap_create(4, 4, self->screen->bpp, WND_TYPE_IMAGE, self);
+
+ if (self->screen->bpp > 8)
+ {
+ g_snprintf(file_path, 255, "%s/xrdp24b.bmp", XRDP_SHARE_PATH);
+ }
+ else
+ {
+ g_snprintf(file_path, 255, "%s/xrdp256.bmp", XRDP_SHARE_PATH);
+ }
+
+ xrdp_bitmap_load(but, file_path, self->palette);
+ but->parent = self->screen;
+ but->owner = self->screen;
+ but->left = self->screen->width - but->width;
+ but->top = self->screen->height - but->height;
+ list_add_item(self->screen->child_list, (long)but);
+
+ /* image */
+ but = xrdp_bitmap_create(4, 4, self->screen->bpp, WND_TYPE_IMAGE, self);
+
+ if (self->screen->bpp > 8)
+ {
+ g_snprintf(file_path, 255, "%s/ad24b.bmp", XRDP_SHARE_PATH);
+ }
+ else
+ {
+ g_snprintf(file_path, 255, "%s/ad256.bmp", XRDP_SHARE_PATH);
+ }
+
+ xrdp_bitmap_load(but, file_path, self->palette);
+ but->parent = self->login_window;
+ but->owner = self->login_window;
+ but->left = 10;
+ but->top = 30;
+ list_add_item(self->login_window->child_list, (long)but);
}
- xrdp_bitmap_load(but, file_path, self->palette);
+
+ /* label */
+ but = xrdp_bitmap_create(60, DEFAULT_EDIT_H, self->screen->bpp, WND_TYPE_LABEL, self);
+ list_add_item(self->login_window->child_list, (long)but);
but->parent = self->login_window;
but->owner = self->login_window;
- but->left = 10;
- but->top = 30;
+ but->left = regular ? 155 : 5;
+ but->top = DEFAULT_ELEMENT_TOP;
+ set_string(&but->caption1, "Module");
+
+ /* combo */
+ combo = xrdp_bitmap_create(DEFAULT_COMBO_W, DEFAULT_COMBO_H, self->screen->bpp, WND_TYPE_COMBO, self);
+ list_add_item(self->login_window->child_list, (long)combo);
+ combo->parent = self->login_window;
+ combo->owner = self->login_window;
+ combo->left = regular ? DEFAULT_WND_LOGIN_W - DEFAULT_COMBO_W - 30 : 70;
+ combo->top = DEFAULT_ELEMENT_TOP;
+ combo->id = 6;
+ combo->tab_stop = 1;
+ xrdp_wm_login_fill_in_combo(self, combo);
+
+ /* button */
+ but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, self->screen->bpp, WND_TYPE_BUTTON, self);
list_add_item(self->login_window->child_list, (long)but);
- }
-
- /* label */
- but = xrdp_bitmap_create(60, DEFAULT_EDIT_H, self->screen->bpp, WND_TYPE_LABEL, self);
- list_add_item(self->login_window->child_list, (long)but);
- but->parent = self->login_window;
- but->owner = self->login_window;
- but->left = regular ? 155 : 5;
- but->top = DEFAULT_ELEMENT_TOP;
- set_string(&but->caption1, "Module");
-
- /* combo */
- combo = xrdp_bitmap_create(DEFAULT_COMBO_W, DEFAULT_COMBO_H, self->screen->bpp, WND_TYPE_COMBO, self);
- list_add_item(self->login_window->child_list, (long)combo);
- combo->parent = self->login_window;
- combo->owner = self->login_window;
- combo->left = regular ? DEFAULT_WND_LOGIN_W - DEFAULT_COMBO_W - 30 : 70;
- combo->top = DEFAULT_ELEMENT_TOP;
- combo->id = 6;
- combo->tab_stop = 1;
- xrdp_wm_login_fill_in_combo(self, combo);
-
- /* button */
- but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, self->screen->bpp, WND_TYPE_BUTTON, self);
- list_add_item(self->login_window->child_list, (long)but);
- but->parent = self->login_window;
- but->owner = self->login_window;
- but->left = regular ? DEFAULT_WND_LOGIN_W - ((DEFAULT_BUTTON_W+10)*3) - 10 : 30;
- but->top = DEFAULT_WND_LOGIN_H - DEFAULT_BUTTON_H - 15;
- but->id = 3;
- set_string(&but->caption1, "OK");
- but->tab_stop = 1;
- self->login_window->default_button = but;
-
- /* button */
- but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, self->screen->bpp, WND_TYPE_BUTTON, self);
- list_add_item(self->login_window->child_list, (long)but);
- but->parent = self->login_window;
- but->owner = self->login_window;
- but->left = regular ? DEFAULT_WND_LOGIN_W - ((DEFAULT_BUTTON_W+10)*2) - 10 : ((log_width - 30) - DEFAULT_BUTTON_W);
- but->top = DEFAULT_WND_LOGIN_H - DEFAULT_BUTTON_H - 15;
- but->id = 2;
- set_string(&but->caption1, "Cancel");
- but->tab_stop = 1;
- self->login_window->esc_button = but;
-
- if (regular)
- {
+ but->parent = self->login_window;
+ but->owner = self->login_window;
+ but->left = regular ? DEFAULT_WND_LOGIN_W - ((DEFAULT_BUTTON_W + 10) * 3) - 10 : 30;
+ but->top = DEFAULT_WND_LOGIN_H - DEFAULT_BUTTON_H - 15;
+ but->id = 3;
+ set_string(&but->caption1, "OK");
+ but->tab_stop = 1;
+ self->login_window->default_button = but;
+
/* button */
but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, self->screen->bpp, WND_TYPE_BUTTON, self);
list_add_item(self->login_window->child_list, (long)but);
but->parent = self->login_window;
but->owner = self->login_window;
- but->left = DEFAULT_WND_LOGIN_W - (DEFAULT_BUTTON_W+10) - 10;
+ but->left = regular ? DEFAULT_WND_LOGIN_W - ((DEFAULT_BUTTON_W + 10) * 2) - 10 : ((log_width - 30) - DEFAULT_BUTTON_W);
but->top = DEFAULT_WND_LOGIN_H - DEFAULT_BUTTON_H - 15;
- but->id = 1;
- set_string(&but->caption1, "Help");
+ but->id = 2;
+ set_string(&but->caption1, "Cancel");
but->tab_stop = 1;
- }
+ self->login_window->esc_button = but;
- /* labels and edits */
- xrdp_wm_show_edits(self, combo);
+ if (regular)
+ {
+ /* button */
+ but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, self->screen->bpp, WND_TYPE_BUTTON, self);
+ list_add_item(self->login_window->child_list, (long)but);
+ but->parent = self->login_window;
+ but->owner = self->login_window;
+ but->left = DEFAULT_WND_LOGIN_W - (DEFAULT_BUTTON_W + 10) - 10;
+ but->top = DEFAULT_WND_LOGIN_H - DEFAULT_BUTTON_H - 15;
+ but->id = 1;
+ set_string(&but->caption1, "Help");
+ but->tab_stop = 1;
+ }
- return 0;
+ /* labels and edits */
+ xrdp_wm_show_edits(self, combo);
+
+ return 0;
}
diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c
index 0b764cc6..e13854ae 100644
--- a/xrdp/xrdp_mm.c
+++ b/xrdp/xrdp_mm.c
@@ -1,42 +1,40 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- module manager
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * module manager
+ */
#include "xrdp.h"
#include "log.h"
#define ACCESS
/*****************************************************************************/
-struct xrdp_mm* APP_CC
-xrdp_mm_create(struct xrdp_wm* owner)
+struct xrdp_mm *APP_CC
+xrdp_mm_create(struct xrdp_wm *owner)
{
- struct xrdp_mm* self;
+ struct xrdp_mm *self;
- self = (struct xrdp_mm*)g_malloc(sizeof(struct xrdp_mm), 1);
- self->wm = owner;
- self->login_names = list_create();
- self->login_names->auto_free = 1;
- self->login_values = list_create();
- self->login_values->auto_free = 1;
- return self;
+ self = (struct xrdp_mm *)g_malloc(sizeof(struct xrdp_mm), 1);
+ self->wm = owner;
+ self->login_names = list_create();
+ self->login_names->auto_free = 1;
+ self->login_values = list_create();
+ self->login_values->auto_free = 1;
+ return self;
}
/*****************************************************************************/
@@ -44,7 +42,7 @@ xrdp_mm_create(struct xrdp_wm* owner)
static long DEFAULT_CC
xrdp_mm_sync_unload(long param1, long param2)
{
- return g_free_library(param1);
+ return g_free_library(param1);
}
/*****************************************************************************/
@@ -52,170 +50,178 @@ xrdp_mm_sync_unload(long param1, long param2)
static long DEFAULT_CC
xrdp_mm_sync_load(long param1, long param2)
{
- long rv;
- char* libname;
+ long rv;
+ char *libname;
- libname = (char*)param1;
- rv = g_load_library(libname);
- return rv;
+ libname = (char *)param1;
+ rv = g_load_library(libname);
+ return rv;
}
/*****************************************************************************/
static void APP_CC
-xrdp_mm_module_cleanup(struct xrdp_mm* self)
+xrdp_mm_module_cleanup(struct xrdp_mm *self)
{
- g_writeln("xrdp_mm_module_cleanup");
- if (self->mod != 0)
- {
- if (self->mod_exit != 0)
+ g_writeln("xrdp_mm_module_cleanup");
+
+ if (self->mod != 0)
+ {
+ if (self->mod_exit != 0)
+ {
+ /* let the module cleanup */
+ self->mod_exit(self->mod);
+ }
+ }
+
+ if (self->mod_handle != 0)
{
- /* let the module cleanup */
- self->mod_exit(self->mod);
+ /* Let the main thread unload the module.*/
+ g_xrdp_sync(xrdp_mm_sync_unload, self->mod_handle, 0);
}
- }
- if (self->mod_handle != 0)
- {
- /* Let the main thread unload the module.*/
- g_xrdp_sync(xrdp_mm_sync_unload, self->mod_handle, 0);
- }
- trans_delete(self->chan_trans);
- self->chan_trans = 0;
- self->chan_trans_up = 0;
- self->mod_init = 0;
- self->mod_exit = 0;
- self->mod = 0;
- self->mod_handle = 0;
+
+ trans_delete(self->chan_trans);
+ self->chan_trans = 0;
+ self->chan_trans_up = 0;
+ self->mod_init = 0;
+ self->mod_exit = 0;
+ self->mod = 0;
+ self->mod_handle = 0;
}
/*****************************************************************************/
void APP_CC
-xrdp_mm_delete(struct xrdp_mm* self)
+xrdp_mm_delete(struct xrdp_mm *self)
{
- if (self == 0)
- {
- return;
- }
- /* free any module stuff */
- xrdp_mm_module_cleanup(self);
- trans_delete(self->sesman_trans);
- self->sesman_trans = 0;
- self->sesman_trans_up = 0;
- list_delete(self->login_names);
- list_delete(self->login_values);
- g_free(self);
+ if (self == 0)
+ {
+ return;
+ }
+
+ /* free any module stuff */
+ xrdp_mm_module_cleanup(self);
+ trans_delete(self->sesman_trans);
+ self->sesman_trans = 0;
+ self->sesman_trans_up = 0;
+ list_delete(self->login_names);
+ list_delete(self->login_values);
+ g_free(self);
}
/*****************************************************************************/
/* Send login information to sesman */
static int APP_CC
-xrdp_mm_send_login(struct xrdp_mm* self)
-{
- struct stream* s;
- int rv;
- int index;
- int count;
- int xserverbpp;
- char* username;
- char* password;
- char* name;
- char* value;
-
- xrdp_wm_log_msg(self->wm, "sending login info to session manager, "
- "please wait...");
- username = 0;
- password = 0;
- self->code = 0;
- xserverbpp = 0;
- count = self->login_names->count;
- for (index = 0; index < count; index++)
- {
- name = (char*)list_get_item(self->login_names, index);
- value = (char*)list_get_item(self->login_values, index);
- if (g_strcasecmp(name, "username") == 0)
- {
- username = value;
- }
- else if (g_strcasecmp(name, "password") == 0)
- {
- password = value;
- }
- else if (g_strcasecmp(name, "lib") == 0)
- {
- if ((g_strcasecmp(value, "libxup.so") == 0) ||
- (g_strcasecmp(value, "xup.dll") == 0))
- {
- self->code = 10;
- }
- }
- else if (g_strcasecmp(name, "xserverbpp") == 0)
- {
- xserverbpp = g_atoi(value);
- }
- }
- if ((username == 0) || (password == 0))
- {
- xrdp_wm_log_msg(self->wm, "Error finding username and password");
- return 1;
- }
-
- s = trans_get_out_s(self->sesman_trans, 8192);
- s_push_layer(s, channel_hdr, 8);
- /* this code is either 0 for Xvnc or 10 for X11rdp */
- out_uint16_be(s, self->code);
- index = g_strlen(username);
- out_uint16_be(s, index);
- out_uint8a(s, username, index);
- index = g_strlen(password);
-
- out_uint16_be(s, index);
- out_uint8a(s, password, index);
- out_uint16_be(s, self->wm->screen->width);
- out_uint16_be(s, self->wm->screen->height);
-
- if (xserverbpp > 0)
- {
- out_uint16_be(s, xserverbpp);
- }
- else
- {
- out_uint16_be(s, self->wm->screen->bpp);
- }
-
- /* send domain */
- index = g_strlen(self->wm->client_info->domain);
- out_uint16_be(s, index);
- out_uint8a(s, self->wm->client_info->domain, index);
-
- /* send program / shell */
- index = g_strlen(self->wm->client_info->program);
- out_uint16_be(s, index);
- out_uint8a(s, self->wm->client_info->program, index);
-
- /* send directory */
- index = g_strlen(self->wm->client_info->directory);
- out_uint16_be(s, index);
- out_uint8a(s, self->wm->client_info->directory, index);
-
- /* send client ip */
- index = g_strlen(self->wm->client_info->client_ip);
- out_uint16_be(s, index);
- out_uint8a(s, self->wm->client_info->client_ip, index);
-
- s_mark_end(s);
-
- s_pop_layer(s, channel_hdr);
- /* Version 0 of the protocol to sesman is currently used by XRDP */
- out_uint32_be(s, 0); /* version */
- index = (int)(s->end - s->data);
- out_uint32_be(s, index); /* size */
-
- rv = trans_force_write(self->sesman_trans);
-
- if (rv != 0) {
- xrdp_wm_log_msg(self->wm, "xrdp_mm_send_login: xrdp_mm_send_login failed");
- }
-
- return rv;
+xrdp_mm_send_login(struct xrdp_mm *self)
+{
+ struct stream *s;
+ int rv;
+ int index;
+ int count;
+ int xserverbpp;
+ char *username;
+ char *password;
+ char *name;
+ char *value;
+
+ xrdp_wm_log_msg(self->wm, "sending login info to session manager, "
+ "please wait...");
+ username = 0;
+ password = 0;
+ self->code = 0;
+ xserverbpp = 0;
+ count = self->login_names->count;
+
+ for (index = 0; index < count; index++)
+ {
+ name = (char *)list_get_item(self->login_names, index);
+ value = (char *)list_get_item(self->login_values, index);
+
+ if (g_strcasecmp(name, "username") == 0)
+ {
+ username = value;
+ }
+ else if (g_strcasecmp(name, "password") == 0)
+ {
+ password = value;
+ }
+ else if (g_strcasecmp(name, "lib") == 0)
+ {
+ if ((g_strcasecmp(value, "libxup.so") == 0) ||
+ (g_strcasecmp(value, "xup.dll") == 0))
+ {
+ self->code = 10;
+ }
+ }
+ else if (g_strcasecmp(name, "xserverbpp") == 0)
+ {
+ xserverbpp = g_atoi(value);
+ }
+ }
+
+ if ((username == 0) || (password == 0))
+ {
+ xrdp_wm_log_msg(self->wm, "Error finding username and password");
+ return 1;
+ }
+
+ s = trans_get_out_s(self->sesman_trans, 8192);
+ s_push_layer(s, channel_hdr, 8);
+ /* this code is either 0 for Xvnc or 10 for X11rdp */
+ out_uint16_be(s, self->code);
+ index = g_strlen(username);
+ out_uint16_be(s, index);
+ out_uint8a(s, username, index);
+ index = g_strlen(password);
+
+ out_uint16_be(s, index);
+ out_uint8a(s, password, index);
+ out_uint16_be(s, self->wm->screen->width);
+ out_uint16_be(s, self->wm->screen->height);
+
+ if (xserverbpp > 0)
+ {
+ out_uint16_be(s, xserverbpp);
+ }
+ else
+ {
+ out_uint16_be(s, self->wm->screen->bpp);
+ }
+
+ /* send domain */
+ index = g_strlen(self->wm->client_info->domain);
+ out_uint16_be(s, index);
+ out_uint8a(s, self->wm->client_info->domain, index);
+
+ /* send program / shell */
+ index = g_strlen(self->wm->client_info->program);
+ out_uint16_be(s, index);
+ out_uint8a(s, self->wm->client_info->program, index);
+
+ /* send directory */
+ index = g_strlen(self->wm->client_info->directory);
+ out_uint16_be(s, index);
+ out_uint8a(s, self->wm->client_info->directory, index);
+
+ /* send client ip */
+ index = g_strlen(self->wm->client_info->client_ip);
+ out_uint16_be(s, index);
+ out_uint8a(s, self->wm->client_info->client_ip, index);
+
+ s_mark_end(s);
+
+ s_pop_layer(s, channel_hdr);
+ /* Version 0 of the protocol to sesman is currently used by XRDP */
+ out_uint32_be(s, 0); /* version */
+ index = (int)(s->end - s->data);
+ out_uint32_be(s, index); /* size */
+
+ rv = trans_force_write(self->sesman_trans);
+
+ if (rv != 0)
+ {
+ xrdp_wm_log_msg(self->wm, "xrdp_mm_send_login: xrdp_mm_send_login failed");
+ }
+
+ return rv;
}
/*****************************************************************************/
@@ -224,744 +230,828 @@ xrdp_mm_send_login(struct xrdp_mm* self)
then it copies the corisponding login_values item into 'dest'
'dest' must be at least 'dest_len' + 1 bytes in size */
static int APP_CC
-xrdp_mm_get_value(struct xrdp_mm* self, char* aname, char* dest, int dest_len)
+xrdp_mm_get_value(struct xrdp_mm *self, char *aname, char *dest, int dest_len)
{
- char* name;
- char* value;
- int index;
- int count;
- int rv;
+ char *name;
+ char *value;
+ int index;
+ int count;
+ int rv;
- rv = 1;
- /* find the library name */
- dest[0] = 0;
- count = self->login_names->count;
- for (index = 0; index < count; index++)
- {
- name = (char*)list_get_item(self->login_names, index);
- value = (char*)list_get_item(self->login_values, index);
- if ((name == 0) || (value == 0))
- {
- break;
- }
- if (g_strcasecmp(name, aname) == 0)
+ rv = 1;
+ /* find the library name */
+ dest[0] = 0;
+ count = self->login_names->count;
+
+ for (index = 0; index < count; index++)
{
- g_strncpy(dest, value, dest_len);
- rv = 0;
+ name = (char *)list_get_item(self->login_names, index);
+ value = (char *)list_get_item(self->login_values, index);
+
+ if ((name == 0) || (value == 0))
+ {
+ break;
+ }
+
+ if (g_strcasecmp(name, aname) == 0)
+ {
+ g_strncpy(dest, value, dest_len);
+ rv = 0;
+ }
}
- }
- return rv;
+ return rv;
}
/*****************************************************************************/
static int APP_CC
-xrdp_mm_setup_mod1(struct xrdp_mm* self)
-{
- void* func;
- char lib[256];
- char text[256];
-
- if (self == 0)
- {
- return 1;
- }
- lib[0] = 0;
- if (xrdp_mm_get_value(self, "lib", lib, 255) != 0)
- {
- g_snprintf(text, 255, "no library name specified in xrdp.ini, please add "
- "lib=libxrdp-vnc.so or similar");
- xrdp_wm_log_msg(self->wm, text);
-
- return 1;
- }
- if (lib[0] == 0)
- {
- g_snprintf(text, 255, "empty library name specified in xrdp.ini, please "
- "add lib=libxrdp-vnc.so or similar");
- xrdp_wm_log_msg(self->wm, text);
-
- return 1;
- }
- if (self->mod_handle == 0)
- {
- /* Let the main thread load the lib,*/
- self->mod_handle = g_xrdp_sync(xrdp_mm_sync_load, (long)lib, 0);
- if (self->mod_handle != 0)
+xrdp_mm_setup_mod1(struct xrdp_mm *self)
+{
+ void *func;
+ char lib[256];
+ char text[256];
+
+ if (self == 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_snprintf(text, 255, "error finding proc mod_init in %s, not a valid "
- "xrdp backend", lib);
- xrdp_wm_log_msg(self->wm, text);
- }
- 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_snprintf(text, 255, "error finding proc mod_exit in %s, not a valid "
- "xrdp backend", lib);
+ return 1;
+ }
+
+ lib[0] = 0;
+
+ if (xrdp_mm_get_value(self, "lib", lib, 255) != 0)
+ {
+ g_snprintf(text, 255, "no library name specified in xrdp.ini, please add "
+ "lib=libxrdp-vnc.so or similar");
xrdp_wm_log_msg(self->wm, text);
- }
- self->mod_exit = (int (*)(struct xrdp_mod*))func;
- if ((self->mod_init != 0) && (self->mod_exit != 0))
- {
- self->mod = self->mod_init();
- if (self->mod != 0)
- {
- g_writeln("loaded module '%s' ok, interface size %d, version %d", lib,
- self->mod->size, self->mod->version);
- }
- }else{
- g_writeln("no mod_init or mod_exit address found");
- }
+
+ return 1;
}
- else
+
+ if (lib[0] == 0)
{
- g_snprintf(text, 255, "error loading %s specified in xrdp.ini, please "
- "add a valid entry like lib=libxrdp-vnc.so or similar", lib);
- xrdp_wm_log_msg(self->wm, text);
- return 1;
+ g_snprintf(text, 255, "empty library name specified in xrdp.ini, please "
+ "add lib=libxrdp-vnc.so or similar");
+ xrdp_wm_log_msg(self->wm, text);
+
+ return 1;
}
- if (self->mod != 0)
+
+ if (self->mod_handle == 0)
{
- self->mod->wm = (long)(self->wm);
- self->mod->server_begin_update = server_begin_update;
- self->mod->server_end_update = server_end_update;
- self->mod->server_bell_trigger = server_bell_trigger;
- 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;
- self->mod->server_create_os_surface = server_create_os_surface;
- self->mod->server_switch_os_surface = server_switch_os_surface;
- self->mod->server_delete_os_surface = server_delete_os_surface;
- self->mod->server_paint_rect_os = server_paint_rect_os;
- self->mod->server_set_hints = server_set_hints;
- self->mod->server_window_new_update = server_window_new_update;
- self->mod->server_window_delete = server_window_delete;
- self->mod->server_window_icon = server_window_icon;
- self->mod->server_window_cached_icon = server_window_cached_icon;
- self->mod->server_notify_new_update = server_notify_new_update;
- self->mod->server_notify_delete = server_notify_delete;
- self->mod->server_monitored_desktop = server_monitored_desktop;
- }
- }
- /* id self->mod is null, there must be a problem */
- if (self->mod == 0)
- {
- DEBUG(("problem loading lib in xrdp_mm_setup_mod1"));
- return 1;
- }
- return 0;
-}
+ /* Let the main thread load the lib,*/
+ self->mod_handle = g_xrdp_sync(xrdp_mm_sync_load, (long)lib, 0);
-/*****************************************************************************/
-static int APP_CC
-xrdp_mm_setup_mod2(struct xrdp_mm* self)
-{
- char text[256];
- char* name;
- char* value;
- int i;
- int rv;
- int key_flags;
- int device_flags;
- int use_uds;
-
- rv = 1; /* failure */
- g_memset(text, 0, sizeof(text));
- if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
- {
- if (self->mod->mod_start(self->mod, self->wm->screen->width,
- self->wm->screen->height,
- self->wm->screen->bpp) != 0)
- {
- g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
- }
- }
- if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
- {
- if (self->display > 0)
- {
- if (self->code == 0) /* Xvnc */
- {
- g_snprintf(text, 255, "%d", 5900 + self->display);
- }
- else if (self->code == 10) /* X11rdp */
- {
- use_uds = 1;
- if (xrdp_mm_get_value(self, "ip", text, 255) == 0)
- {
- if (g_strcmp(text, "127.0.0.1") != 0)
- {
- use_uds = 0;
- }
- }
- if (use_uds)
- {
- g_snprintf(text, 255, "/tmp/.xrdp/xrdp_display_%d", self->display);
+ 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_snprintf(text, 255, "error finding proc mod_init in %s, not a valid "
+ "xrdp backend", lib);
+ xrdp_wm_log_msg(self->wm, text);
+ }
+
+ 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_snprintf(text, 255, "error finding proc mod_exit in %s, not a valid "
+ "xrdp backend", lib);
+ xrdp_wm_log_msg(self->wm, text);
+ }
+
+ self->mod_exit = (int ( *)(struct xrdp_mod *))func;
+
+ if ((self->mod_init != 0) && (self->mod_exit != 0))
+ {
+ self->mod = self->mod_init();
+
+ if (self->mod != 0)
+ {
+ g_writeln("loaded module '%s' ok, interface size %d, version %d", lib,
+ self->mod->size, self->mod->version);
+ }
+ }
+ else
+ {
+ g_writeln("no mod_init or mod_exit address found");
+ }
}
else
{
- g_snprintf(text, 255, "%d", 6200 + self->display);
+ g_snprintf(text, 255, "error loading %s specified in xrdp.ini, please "
+ "add a valid entry like lib=libxrdp-vnc.so or similar", lib);
+ xrdp_wm_log_msg(self->wm, text);
+ return 1;
+ }
+
+ if (self->mod != 0)
+ {
+ self->mod->wm = (long)(self->wm);
+ self->mod->server_begin_update = server_begin_update;
+ self->mod->server_end_update = server_end_update;
+ self->mod->server_bell_trigger = server_bell_trigger;
+ 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;
+ self->mod->server_create_os_surface = server_create_os_surface;
+ self->mod->server_switch_os_surface = server_switch_os_surface;
+ self->mod->server_delete_os_surface = server_delete_os_surface;
+ self->mod->server_paint_rect_os = server_paint_rect_os;
+ self->mod->server_set_hints = server_set_hints;
+ self->mod->server_window_new_update = server_window_new_update;
+ self->mod->server_window_delete = server_window_delete;
+ self->mod->server_window_icon = server_window_icon;
+ self->mod->server_window_cached_icon = server_window_cached_icon;
+ self->mod->server_notify_new_update = server_notify_new_update;
+ self->mod->server_notify_delete = server_notify_delete;
+ self->mod->server_monitored_desktop = server_monitored_desktop;
}
- }
- else
- {
- g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
- }
}
- }
- if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
- {
- /* this adds the port to the end of the list, it will already be in
- the list as -1
- the module should use the last one */
- if (g_strlen(text) > 0)
+
+ /* id self->mod is null, there must be a problem */
+ if (self->mod == 0)
{
- list_add_item(self->login_names, (long)g_strdup("port"));
- list_add_item(self->login_values, (long)g_strdup(text));
+ DEBUG(("problem loading lib in xrdp_mm_setup_mod1"));
+ return 1;
}
- /* always set these */
- self->mod->mod_set_param(self->mod, "client_info",
- (char*)(self->wm->session->client_info));
+ return 0;
+}
- name = self->wm->session->client_info->hostname;
- self->mod->mod_set_param(self->mod, "hostname", name);
- g_snprintf(text, 255, "%d", self->wm->session->client_info->keylayout);
- self->mod->mod_set_param(self->mod, "keylayout", text);
- for (i = 0; i < self->login_names->count; i++)
- {
- name = (char*)list_get_item(self->login_names, i);
- value = (char*)list_get_item(self->login_values, i);
- self->mod->mod_set_param(self->mod, name, value);
- }
- /* connect */
- if (self->mod->mod_connect(self->mod) == 0)
- {
- rv = 0; /* connect success */
- }
- }
- if (rv == 0)
- {
- /* sync modifiers */
- key_flags = 0;
- device_flags = 0;
- if (self->wm->scroll_lock)
+/*****************************************************************************/
+static int APP_CC
+xrdp_mm_setup_mod2(struct xrdp_mm *self)
+{
+ char text[256];
+ char *name;
+ char *value;
+ int i;
+ int rv;
+ int key_flags;
+ int device_flags;
+ int use_uds;
+
+ rv = 1; /* failure */
+ g_memset(text, 0, sizeof(text));
+
+ if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
{
- key_flags |= 1;
+ if (self->mod->mod_start(self->mod, self->wm->screen->width,
+ self->wm->screen->height,
+ self->wm->screen->bpp) != 0)
+ {
+ g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
+ }
}
- if (self->wm->num_lock)
+
+ if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
{
- key_flags |= 2;
+ if (self->display > 0)
+ {
+ if (self->code == 0) /* Xvnc */
+ {
+ g_snprintf(text, 255, "%d", 5900 + self->display);
+ }
+ else if (self->code == 10) /* X11rdp */
+ {
+ use_uds = 1;
+
+ if (xrdp_mm_get_value(self, "ip", text, 255) == 0)
+ {
+ if (g_strcmp(text, "127.0.0.1") != 0)
+ {
+ use_uds = 0;
+ }
+ }
+
+ if (use_uds)
+ {
+ g_snprintf(text, 255, "/tmp/.xrdp/xrdp_display_%d", self->display);
+ }
+ else
+ {
+ g_snprintf(text, 255, "%d", 6200 + self->display);
+ }
+ }
+ else
+ {
+ g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
+ }
+ }
}
- if (self->wm->caps_lock)
+
+ if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
{
- key_flags |= 4;
+ /* this adds the port to the end of the list, it will already be in
+ the list as -1
+ the module should use the last one */
+ if (g_strlen(text) > 0)
+ {
+ list_add_item(self->login_names, (long)g_strdup("port"));
+ list_add_item(self->login_values, (long)g_strdup(text));
+ }
+
+ /* always set these */
+
+ self->mod->mod_set_param(self->mod, "client_info",
+ (char *)(self->wm->session->client_info));
+
+ name = self->wm->session->client_info->hostname;
+ self->mod->mod_set_param(self->mod, "hostname", name);
+ g_snprintf(text, 255, "%d", self->wm->session->client_info->keylayout);
+ self->mod->mod_set_param(self->mod, "keylayout", text);
+
+ for (i = 0; i < self->login_names->count; i++)
+ {
+ name = (char *)list_get_item(self->login_names, i);
+ value = (char *)list_get_item(self->login_values, i);
+ self->mod->mod_set_param(self->mod, name, value);
+ }
+
+ /* connect */
+ if (self->mod->mod_connect(self->mod) == 0)
+ {
+ rv = 0; /* connect success */
+ }
}
- if (self->mod != 0)
+
+ if (rv == 0)
{
- if (self->mod->mod_event != 0)
- {
- self->mod->mod_event(self->mod, 17, key_flags, device_flags,
- key_flags, device_flags);
- }
+ /* sync modifiers */
+ key_flags = 0;
+ device_flags = 0;
+
+ if (self->wm->scroll_lock)
+ {
+ key_flags |= 1;
+ }
+
+ if (self->wm->num_lock)
+ {
+ key_flags |= 2;
+ }
+
+ if (self->wm->caps_lock)
+ {
+ key_flags |= 4;
+ }
+
+ if (self->mod != 0)
+ {
+ if (self->mod->mod_event != 0)
+ {
+ self->mod->mod_event(self->mod, 17, key_flags, device_flags,
+ key_flags, device_flags);
+ }
+ }
}
- }
- return rv;
+
+ return rv;
}
/*****************************************************************************/
/* returns error
send a list of channels to the channel handler */
static int APP_CC
-xrdp_mm_trans_send_channel_setup(struct xrdp_mm* self, struct trans* trans)
-{
- int index;
- int chan_id;
- int chan_flags;
- int size;
- struct stream* s;
- char chan_name[256];
-
- g_memset(chan_name,0,sizeof(char) * 256);
-
- s = trans_get_out_s(trans, 8192);
- if (s == 0)
- {
- return 1;
- }
- s_push_layer(s, iso_hdr, 8);
- s_push_layer(s, mcs_hdr, 8);
- s_push_layer(s, sec_hdr, 2);
- index = 0;
- while (libxrdp_query_channel(self->wm->session, index, chan_name,
- &chan_flags) == 0)
- {
- chan_id = libxrdp_get_channel_id(self->wm->session, chan_name);
- out_uint8a(s, chan_name, 8);
- out_uint16_le(s, chan_id);
- out_uint16_le(s, chan_flags);
- index++;
- }
- s_mark_end(s);
- s_pop_layer(s, sec_hdr);
- out_uint16_le(s, index);
- s_pop_layer(s, mcs_hdr);
- size = (int)(s->end - s->p);
- out_uint32_le(s, 3); /* msg id */
- out_uint32_le(s, size); /* msg size */
- s_pop_layer(s, iso_hdr);
- size = (int)(s->end - s->p);
- out_uint32_le(s, 0); /* version */
- out_uint32_le(s, size); /* block size */
- return trans_force_write(trans);
+xrdp_mm_trans_send_channel_setup(struct xrdp_mm *self, struct trans *trans)
+{
+ int index;
+ int chan_id;
+ int chan_flags;
+ int size;
+ struct stream *s;
+ char chan_name[256];
+
+ g_memset(chan_name, 0, sizeof(char) * 256);
+
+ s = trans_get_out_s(trans, 8192);
+
+ if (s == 0)
+ {
+ return 1;
+ }
+
+ s_push_layer(s, iso_hdr, 8);
+ s_push_layer(s, mcs_hdr, 8);
+ s_push_layer(s, sec_hdr, 2);
+ index = 0;
+
+ while (libxrdp_query_channel(self->wm->session, index, chan_name,
+ &chan_flags) == 0)
+ {
+ chan_id = libxrdp_get_channel_id(self->wm->session, chan_name);
+ out_uint8a(s, chan_name, 8);
+ out_uint16_le(s, chan_id);
+ out_uint16_le(s, chan_flags);
+ index++;
+ }
+
+ s_mark_end(s);
+ s_pop_layer(s, sec_hdr);
+ out_uint16_le(s, index);
+ s_pop_layer(s, mcs_hdr);
+ size = (int)(s->end - s->p);
+ out_uint32_le(s, 3); /* msg id */
+ out_uint32_le(s, size); /* msg size */
+ s_pop_layer(s, iso_hdr);
+ size = (int)(s->end - s->p);
+ out_uint32_le(s, 0); /* version */
+ out_uint32_le(s, size); /* block size */
+ return trans_force_write(trans);
}
/*****************************************************************************/
/* returns error */
static int APP_CC
-xrdp_mm_trans_send_channel_data_response(struct xrdp_mm* self,
- struct trans* trans)
+xrdp_mm_trans_send_channel_data_response(struct xrdp_mm *self,
+ struct trans *trans)
{
- struct stream* s;
+ struct stream *s;
+
+ s = trans_get_out_s(trans, 8192);
+
+ if (s == 0)
+ {
+ return 1;
+ }
- s = trans_get_out_s(trans, 8192);
- if (s == 0)
- {
- return 1;
- }
- out_uint32_le(s, 0); /* version */
- out_uint32_le(s, 8 + 8); /* size */
- out_uint32_le(s, 7); /* msg id */
- out_uint32_le(s, 8); /* size */
- s_mark_end(s);
- return trans_force_write(trans);
+ out_uint32_le(s, 0); /* version */
+ out_uint32_le(s, 8 + 8); /* size */
+ out_uint32_le(s, 7); /* msg id */
+ out_uint32_le(s, 8); /* size */
+ s_mark_end(s);
+ return trans_force_write(trans);
}
/*****************************************************************************/
/* returns error
init is done, sent channel setup */
static int APP_CC
-xrdp_mm_trans_process_init_response(struct xrdp_mm* self, struct trans* trans)
+xrdp_mm_trans_process_init_response(struct xrdp_mm *self, struct trans *trans)
{
- return xrdp_mm_trans_send_channel_setup(self, trans);
+ return xrdp_mm_trans_send_channel_setup(self, trans);
}
/*****************************************************************************/
/* returns error
data coming in from the channel handler, send it to the client */
static int APP_CC
-xrdp_mm_trans_process_channel_data(struct xrdp_mm* self, struct trans* trans)
-{
- struct stream* s;
- int size;
- int total_size;
- int chan_id;
- int chan_flags;
- int rv;
-
- s = trans_get_in_s(trans);
- if (s == 0)
- {
- return 1;
- }
- in_uint16_le(s, chan_id);
- in_uint16_le(s, chan_flags);
- in_uint16_le(s, size);
- in_uint32_le(s, total_size);
- rv = xrdp_mm_trans_send_channel_data_response(self, trans);
- if (rv == 0)
- {
- rv = libxrdp_send_to_channel(self->wm->session, chan_id, s->p, size, total_size,
- chan_flags);
- }
- return rv;
+xrdp_mm_trans_process_channel_data(struct xrdp_mm *self, struct trans *trans)
+{
+ struct stream *s;
+ int size;
+ int total_size;
+ int chan_id;
+ int chan_flags;
+ int rv;
+
+ s = trans_get_in_s(trans);
+
+ if (s == 0)
+ {
+ return 1;
+ }
+
+ in_uint16_le(s, chan_id);
+ in_uint16_le(s, chan_flags);
+ in_uint16_le(s, size);
+ in_uint32_le(s, total_size);
+ rv = xrdp_mm_trans_send_channel_data_response(self, trans);
+
+ if (rv == 0)
+ {
+ rv = libxrdp_send_to_channel(self->wm->session, chan_id, s->p, size, total_size,
+ chan_flags);
+ }
+
+ return rv;
}
/*****************************************************************************/
/* returns error
process a message for the channel handler */
static int APP_CC
-xrdp_mm_chan_process_msg(struct xrdp_mm* self, struct trans* trans,
- struct stream* s)
-{
- int rv;
- int id;
- int size;
- char* next_msg;
-
- rv = 0;
- while (s_check_rem(s, 8))
- {
- next_msg = s->p;
- in_uint32_le(s, id);
- in_uint32_le(s, size);
- next_msg += size;
- switch (id)
- {
- case 2: /* channel init response */
- rv = xrdp_mm_trans_process_init_response(self, trans);
- break;
- case 4: /* channel setup response */
- break;
- case 6: /* channel data response */
- break;
- case 8: /* channel data */
- rv = xrdp_mm_trans_process_channel_data(self, trans);
- break;
- default:
- g_writeln("xrdp_mm_chan_process_msg: unknown id %d", id);
- break;
- }
- if (rv != 0)
+xrdp_mm_chan_process_msg(struct xrdp_mm *self, struct trans *trans,
+ struct stream *s)
+{
+ int rv;
+ int id;
+ int size;
+ char *next_msg;
+
+ rv = 0;
+
+ while (s_check_rem(s, 8))
{
- break;
+ next_msg = s->p;
+ in_uint32_le(s, id);
+ in_uint32_le(s, size);
+ next_msg += size;
+
+ switch (id)
+ {
+ case 2: /* channel init response */
+ rv = xrdp_mm_trans_process_init_response(self, trans);
+ break;
+ case 4: /* channel setup response */
+ break;
+ case 6: /* channel data response */
+ break;
+ case 8: /* channel data */
+ rv = xrdp_mm_trans_process_channel_data(self, trans);
+ break;
+ default:
+ g_writeln("xrdp_mm_chan_process_msg: unknown id %d", id);
+ break;
+ }
+
+ if (rv != 0)
+ {
+ break;
+ }
+
+ s->p = next_msg;
}
- s->p = next_msg;
- }
- return rv;
+
+ return rv;
}
/*****************************************************************************/
/* this is callback from trans obj
returns error */
static int APP_CC
-xrdp_mm_chan_data_in(struct trans* trans)
-{
- struct xrdp_mm* self;
- struct stream* s;
- int id;
- int size;
- int error;
-
- if (trans == 0)
- {
- return 1;
- }
- self = (struct xrdp_mm*)(trans->callback_data);
- s = trans_get_in_s(trans);
- if (s == 0)
- {
- return 1;
- }
- in_uint32_le(s, id);
- in_uint32_le(s, size);
- error = trans_force_read(trans, size - 8);
- if (error == 0)
- {
- /* here, the entire message block is read in, process it */
- error = xrdp_mm_chan_process_msg(self, trans, s);
- }
- return error;
+xrdp_mm_chan_data_in(struct trans *trans)
+{
+ struct xrdp_mm *self;
+ struct stream *s;
+ int id;
+ int size;
+ int error;
+
+ if (trans == 0)
+ {
+ return 1;
+ }
+
+ self = (struct xrdp_mm *)(trans->callback_data);
+ s = trans_get_in_s(trans);
+
+ if (s == 0)
+ {
+ return 1;
+ }
+
+ in_uint32_le(s, id);
+ in_uint32_le(s, size);
+ error = trans_force_read(trans, size - 8);
+
+ if (error == 0)
+ {
+ /* here, the entire message block is read in, process it */
+ error = xrdp_mm_chan_process_msg(self, trans, s);
+ }
+
+ return error;
}
/*****************************************************************************/
static int APP_CC
-xrdp_mm_chan_send_init(struct xrdp_mm* self)
+xrdp_mm_chan_send_init(struct xrdp_mm *self)
{
- struct stream* s;
+ struct stream *s;
+
+ s = trans_get_out_s(self->chan_trans, 8192);
- s = trans_get_out_s(self->chan_trans, 8192);
- if (s == 0)
- {
- return 1;
- }
- out_uint32_le(s, 0); /* version */
- out_uint32_le(s, 8 + 8); /* size */
- out_uint32_le(s, 1); /* msg id */
- out_uint32_le(s, 8); /* size */
- s_mark_end(s);
- return trans_force_write(self->chan_trans);
+ if (s == 0)
+ {
+ return 1;
+ }
+
+ out_uint32_le(s, 0); /* version */
+ out_uint32_le(s, 8 + 8); /* size */
+ out_uint32_le(s, 1); /* msg id */
+ out_uint32_le(s, 8); /* size */
+ s_mark_end(s);
+ return trans_force_write(self->chan_trans);
}
/*****************************************************************************/
/* connect to chansrv */
static int APP_CC
-xrdp_mm_connect_chansrv(struct xrdp_mm* self, char* ip, char* port)
-{
- int index;
-
- self->usechansrv = 1;
-
- /* connect channel redir */
- if ((ip == 0) || (g_strcmp(ip, "127.0.0.1") == 0) || (ip[0] == 0))
- {
- /* unix socket */
- self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
- }
- else
- {
- /* tcp */
- self->chan_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
- }
- self->chan_trans->trans_data_in = xrdp_mm_chan_data_in;
- self->chan_trans->header_size = 8;
- self->chan_trans->callback_data = self;
- /* try to connect up to 4 times */
- for (index = 0; index < 4; index++)
- {
- if (trans_connect(self->chan_trans, ip, port, 3000) == 0)
- {
- self->chan_trans_up = 1;
- break;
- }
- g_sleep(1000);
- g_writeln("xrdp_mm_connect_chansrv: connect failed "
- "trying again...");
- }
- if (!(self->chan_trans_up))
- {
- g_writeln("xrdp_mm_connect_chansrv: error in trans_connect "
- "chan");
- }
- if (self->chan_trans_up)
- {
- if (xrdp_mm_chan_send_init(self) != 0)
- {
- g_writeln("xrdp_mm_connect_chansrv: error in "
- "xrdp_mm_chan_send_init");
+xrdp_mm_connect_chansrv(struct xrdp_mm *self, char *ip, char *port)
+{
+ int index;
+
+ self->usechansrv = 1;
+
+ /* connect channel redir */
+ if ((ip == 0) || (g_strcmp(ip, "127.0.0.1") == 0) || (ip[0] == 0))
+ {
+ /* unix socket */
+ self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
}
else
{
- g_writeln("xrdp_mm_connect_chansrv: chansrv connect successful");
+ /* tcp */
+ self->chan_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
}
- }
- return 0;
+
+ self->chan_trans->trans_data_in = xrdp_mm_chan_data_in;
+ self->chan_trans->header_size = 8;
+ self->chan_trans->callback_data = self;
+
+ /* try to connect up to 4 times */
+ for (index = 0; index < 4; index++)
+ {
+ if (trans_connect(self->chan_trans, ip, port, 3000) == 0)
+ {
+ self->chan_trans_up = 1;
+ break;
+ }
+
+ g_sleep(1000);
+ g_writeln("xrdp_mm_connect_chansrv: connect failed "
+ "trying again...");
+ }
+
+ if (!(self->chan_trans_up))
+ {
+ g_writeln("xrdp_mm_connect_chansrv: error in trans_connect "
+ "chan");
+ }
+
+ if (self->chan_trans_up)
+ {
+ if (xrdp_mm_chan_send_init(self) != 0)
+ {
+ g_writeln("xrdp_mm_connect_chansrv: error in "
+ "xrdp_mm_chan_send_init");
+ }
+ else
+ {
+ g_writeln("xrdp_mm_connect_chansrv: chansrv connect successful");
+ }
+ }
+
+ return 0;
}
-static void cleanup_sesman_connection(struct xrdp_mm* self)
+static void cleanup_sesman_connection(struct xrdp_mm *self)
{
- self->delete_sesman_trans = 1;
- self->connected_state = 0;
- if (self->wm->login_mode != 10)
- {
- xrdp_wm_set_login_mode(self->wm, 11);
- xrdp_mm_module_cleanup(self);
- }
+ self->delete_sesman_trans = 1;
+ self->connected_state = 0;
+
+ if (self->wm->login_mode != 10)
+ {
+ xrdp_wm_set_login_mode(self->wm, 11);
+ xrdp_mm_module_cleanup(self);
+ }
}
/*****************************************************************************/
static int APP_CC
-xrdp_mm_process_login_response(struct xrdp_mm* self, struct stream* s)
-{
- int ok;
- int display;
- int rv;
- char text[256];
- char ip[256];
- char port[256];
-
- rv = 0;
- in_uint16_be(s, ok);
- in_uint16_be(s, display);
- if (ok)
- {
- self->display = display;
- g_snprintf(text, 255, "xrdp_mm_process_login_response: login successful "
- "for display %d", display);
- xrdp_wm_log_msg(self->wm, text);
- if (xrdp_mm_setup_mod1(self) == 0)
- {
- if (xrdp_mm_setup_mod2(self) == 0)
- {
- xrdp_mm_get_value(self, "ip", ip, 255);
- xrdp_wm_set_login_mode(self->wm, 10);
- self->wm->dragging = 0;
- /* connect channel redir */
- if ((ip == 0) || (g_strcmp(ip, "127.0.0.1") == 0) || (ip[0] == 0))
- {
- g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + display);
- }
- else
+xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s)
+{
+ int ok;
+ int display;
+ int rv;
+ char text[256];
+ char ip[256];
+ char port[256];
+
+ rv = 0;
+ in_uint16_be(s, ok);
+ in_uint16_be(s, display);
+
+ if (ok)
+ {
+ self->display = display;
+ g_snprintf(text, 255, "xrdp_mm_process_login_response: login successful "
+ "for display %d", display);
+ xrdp_wm_log_msg(self->wm, text);
+
+ if (xrdp_mm_setup_mod1(self) == 0)
{
- g_snprintf(port, 255, "%d", 7200 + display);
+ if (xrdp_mm_setup_mod2(self) == 0)
+ {
+ xrdp_mm_get_value(self, "ip", ip, 255);
+ xrdp_wm_set_login_mode(self->wm, 10);
+ self->wm->dragging = 0;
+
+ /* connect channel redir */
+ if ((ip == 0) || (g_strcmp(ip, "127.0.0.1") == 0) || (ip[0] == 0))
+ {
+ g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + display);
+ }
+ else
+ {
+ g_snprintf(port, 255, "%d", 7200 + display);
+ }
+
+ xrdp_mm_connect_chansrv(self, ip, port);
+ }
}
- xrdp_mm_connect_chansrv(self, ip, port);
- }
}
- }
- else
- {
- xrdp_wm_log_msg(self->wm, "xrdp_mm_process_login_response: "
- "login failed");
- }
- cleanup_sesman_connection(self);
- return rv;
+ else
+ {
+ xrdp_wm_log_msg(self->wm, "xrdp_mm_process_login_response: "
+ "login failed");
+ }
+
+ cleanup_sesman_connection(self);
+ return rv;
}
/*****************************************************************************/
static int
-xrdp_mm_get_sesman_port(char* port, int port_bytes)
-{
- int fd;
- int error;
- int index;
- char* val;
- char cfg_file[256];
- struct list* names;
- struct list* values;
-
- g_memset(cfg_file,0,sizeof(char) * 256);
- /* default to port 3350 */
- g_strncpy(port, "3350", port_bytes - 1);
- /* see if port is in xrdp.ini file */
- g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);
- fd = g_file_open(cfg_file);
- if (fd > 0)
- {
- names = list_create();
- names->auto_free = 1;
- values = list_create();
- values->auto_free = 1;
- if (file_read_section(fd, "Globals", names, values) == 0)
- {
- for (index = 0; index < names->count; index++)
- {
- val = (char*)list_get_item(names, index);
- if (val != 0)
- {
- if (g_strcasecmp(val, "ListenPort") == 0)
- {
- val = (char*)list_get_item(values, index);
- error = g_atoi(val);
- if ((error > 0) && (error < 65000))
+xrdp_mm_get_sesman_port(char *port, int port_bytes)
+{
+ int fd;
+ int error;
+ int index;
+ char *val;
+ char cfg_file[256];
+ struct list *names;
+ struct list *values;
+
+ g_memset(cfg_file, 0, sizeof(char) * 256);
+ /* default to port 3350 */
+ g_strncpy(port, "3350", port_bytes - 1);
+ /* see if port is in xrdp.ini file */
+ g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);
+ fd = g_file_open(cfg_file);
+
+ if (fd > 0)
+ {
+ names = list_create();
+ names->auto_free = 1;
+ values = list_create();
+ values->auto_free = 1;
+
+ if (file_read_section(fd, "Globals", names, values) == 0)
+ {
+ for (index = 0; index < names->count; index++)
{
- g_strncpy(port, val, port_bytes - 1);
+ val = (char *)list_get_item(names, index);
+
+ if (val != 0)
+ {
+ if (g_strcasecmp(val, "ListenPort") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ error = g_atoi(val);
+
+ if ((error > 0) && (error < 65000))
+ {
+ g_strncpy(port, val, port_bytes - 1);
+ }
+
+ break;
+ }
+ }
}
- break;
- }
}
- }
+
+ list_delete(names);
+ list_delete(values);
+ g_file_close(fd);
}
- list_delete(names);
- list_delete(values);
- g_file_close(fd);
- }
- return 0;
+ return 0;
}
/*****************************************************************************/
/* returns error
data coming from client that need to go to channel handler */
int APP_CC
-xrdp_mm_process_channel_data(struct xrdp_mm* self, tbus param1, tbus param2,
+xrdp_mm_process_channel_data(struct xrdp_mm *self, tbus param1, tbus param2,
tbus param3, tbus param4)
{
- struct stream* s;
- int rv;
- int length;
- int total_length;
- int flags;
- int id;
- char* data;
-
- rv = 0;
- if ((self->chan_trans != 0) && self->chan_trans_up)
- {
- s = trans_get_out_s(self->chan_trans, 8192);
- if (s != 0)
- {
- id = LOWORD(param1);
- flags = HIWORD(param1);
- length = param2;
- data = (char*)param3;
- total_length = param4;
- if (total_length < length)
- {
- g_writeln("WARNING in xrdp_mm_process_channel_data(): total_len < length");
- total_length = length;
- }
- out_uint32_le(s, 0); /* version */
- out_uint32_le(s, 8 + 8 + 2 + 2 + 2 + 4 + length);
- out_uint32_le(s, 5); /* msg id */
- out_uint32_le(s, 8 + 2 + 2 + 2 + 4 + length);
- out_uint16_le(s, id);
- out_uint16_le(s, flags);
- out_uint16_le(s, length);
- out_uint32_le(s, total_length);
- out_uint8a(s, data, length);
- s_mark_end(s);
- rv = trans_force_write(self->chan_trans);
- }
- }
-
- return rv;
+ struct stream *s;
+ int rv;
+ int length;
+ int total_length;
+ int flags;
+ int id;
+ char *data;
+
+ rv = 0;
+
+ if ((self->chan_trans != 0) && self->chan_trans_up)
+ {
+ s = trans_get_out_s(self->chan_trans, 8192);
+
+ if (s != 0)
+ {
+ id = LOWORD(param1);
+ flags = HIWORD(param1);
+ length = param2;
+ data = (char *)param3;
+ total_length = param4;
+
+ if (total_length < length)
+ {
+ g_writeln("WARNING in xrdp_mm_process_channel_data(): total_len < length");
+ total_length = length;
+ }
+
+ out_uint32_le(s, 0); /* version */
+ out_uint32_le(s, 8 + 8 + 2 + 2 + 2 + 4 + length);
+ out_uint32_le(s, 5); /* msg id */
+ out_uint32_le(s, 8 + 2 + 2 + 2 + 4 + length);
+ out_uint16_le(s, id);
+ out_uint16_le(s, flags);
+ out_uint16_le(s, length);
+ out_uint32_le(s, total_length);
+ out_uint8a(s, data, length);
+ s_mark_end(s);
+ rv = trans_force_write(self->chan_trans);
+ }
+ }
+
+ return rv;
}
/*****************************************************************************/
/* This is the callback registered for sesman communication replies. */
static int APP_CC
-xrdp_mm_sesman_data_in(struct trans* trans)
-{
- struct xrdp_mm* self;
- struct stream* s;
- int version;
- int size;
- int error;
- int code;
-
- if (trans == 0)
- {
- return 1;
- }
- self = (struct xrdp_mm*)(trans->callback_data);
- s = trans_get_in_s(trans);
- if (s == 0)
- {
- return 1;
- }
- in_uint32_be(s, version);
- in_uint32_be(s, size);
- error = trans_force_read(trans, size - 8);
- if (error == 0)
- {
- in_uint16_be(s, code);
- switch (code)
- {
- /* even when the request is denied the reply will hold 3 as the command. */
- case 3:
- error = xrdp_mm_process_login_response(self, s);
- break;
- default:
- xrdp_wm_log_msg(self->wm, "An undefined reply code was received from sesman");
- g_writeln("Fatal xrdp_mm_sesman_data_in: unknown cmd code %d", code);
- cleanup_sesman_connection(self);
- break;
- }
- }
-
- return error;
+xrdp_mm_sesman_data_in(struct trans *trans)
+{
+ struct xrdp_mm *self;
+ struct stream *s;
+ int version;
+ int size;
+ int error;
+ int code;
+
+ if (trans == 0)
+ {
+ return 1;
+ }
+
+ self = (struct xrdp_mm *)(trans->callback_data);
+ s = trans_get_in_s(trans);
+
+ if (s == 0)
+ {
+ return 1;
+ }
+
+ in_uint32_be(s, version);
+ in_uint32_be(s, size);
+ error = trans_force_read(trans, size - 8);
+
+ if (error == 0)
+ {
+ in_uint16_be(s, code);
+
+ switch (code)
+ {
+ /* even when the request is denied the reply will hold 3 as the command. */
+ case 3:
+ error = xrdp_mm_process_login_response(self, s);
+ break;
+ default:
+ xrdp_wm_log_msg(self->wm, "An undefined reply code was received from sesman");
+ g_writeln("Fatal xrdp_mm_sesman_data_in: unknown cmd code %d", code);
+ cleanup_sesman_connection(self);
+ break;
+ }
+ }
+
+ return error;
}
#ifdef ACCESS
@@ -969,104 +1059,112 @@ xrdp_mm_sesman_data_in(struct trans* trans)
/* return 0 on success */
int access_control(char *username, char *password, char *srv)
{
- int reply;
- int rec = 1; // failure
- struct stream* in_s;
- struct stream* out_s;
- unsigned long version;
- unsigned short int dummy;
- unsigned short int ok;
- unsigned short int code;
- unsigned long size;
- int index;
- int socket = g_tcp_socket();
- if (socket > 0)
- {
- /* we use a blocking socket here */
- reply = g_tcp_connect(socket, srv, "3350");
- if (reply == 0)
- {
- make_stream(in_s);
- init_stream(in_s, 500);
- make_stream(out_s);
- init_stream(out_s, 500);
- s_push_layer(out_s, channel_hdr, 8);
- out_uint16_be(out_s, 4); /*0x04 means SCP_GW_AUTHENTICATION*/
- index = g_strlen(username);
- out_uint16_be(out_s, index);
- out_uint8a(out_s, username, index);
-
- index = g_strlen(password);
- out_uint16_be(out_s, index);
- out_uint8a(out_s, password, index);
- s_mark_end(out_s);
- s_pop_layer(out_s, channel_hdr);
- out_uint32_be(out_s, 0); /* version */
- index = (int)(out_s->end - out_s->data);
- out_uint32_be(out_s, index); /* size */
- /* g_writeln("Number of data to send : %d",index); */
- reply = g_tcp_send(socket, out_s->data, index, 0);
- free_stream(out_s);
- if (reply > 0)
- {
- /* We wait in 5 sec for a reply from sesman*/
- if (g_tcp_can_recv(socket, 5000))
- {
- reply = g_tcp_recv(socket, in_s->end, 500, 0);
- if (reply > 0)
- {
- in_s->end = in_s->end + reply;
- in_uint32_be(in_s, version);
- /*g_writeln("Version number in reply from sesman: %d",version) ; */
- in_uint32_be(in_s, size);
- if ((size == 14) && (version == 0))
+ int reply;
+ int rec = 1; // failure
+ struct stream *in_s;
+ struct stream *out_s;
+ unsigned long version;
+ unsigned short int dummy;
+ unsigned short int ok;
+ unsigned short int code;
+ unsigned long size;
+ int index;
+ int socket = g_tcp_socket();
+
+ if (socket > 0)
+ {
+ /* we use a blocking socket here */
+ reply = g_tcp_connect(socket, srv, "3350");
+
+ if (reply == 0)
+ {
+ make_stream(in_s);
+ init_stream(in_s, 500);
+ make_stream(out_s);
+ init_stream(out_s, 500);
+ s_push_layer(out_s, channel_hdr, 8);
+ out_uint16_be(out_s, 4); /*0x04 means SCP_GW_AUTHENTICATION*/
+ index = g_strlen(username);
+ out_uint16_be(out_s, index);
+ out_uint8a(out_s, username, index);
+
+ index = g_strlen(password);
+ out_uint16_be(out_s, index);
+ out_uint8a(out_s, password, index);
+ s_mark_end(out_s);
+ s_pop_layer(out_s, channel_hdr);
+ out_uint32_be(out_s, 0); /* version */
+ index = (int)(out_s->end - out_s->data);
+ out_uint32_be(out_s, index); /* size */
+ /* g_writeln("Number of data to send : %d",index); */
+ reply = g_tcp_send(socket, out_s->data, index, 0);
+ free_stream(out_s);
+
+ if (reply > 0)
{
- in_uint16_be(in_s, code);
- in_uint16_be(in_s, ok);
- in_uint16_be(in_s, dummy);
- if (code != 4)
- {
- log_message(LOG_LEVEL_ERROR, "Returned cmd code from "
- "sesman is corrupt");
- }
- else
- {
- rec = ok; /* here we read the reply from the access control */
- }
+ /* We wait in 5 sec for a reply from sesman*/
+ if (g_tcp_can_recv(socket, 5000))
+ {
+ reply = g_tcp_recv(socket, in_s->end, 500, 0);
+
+ if (reply > 0)
+ {
+ in_s->end = in_s->end + reply;
+ in_uint32_be(in_s, version);
+ /*g_writeln("Version number in reply from sesman: %d",version) ; */
+ in_uint32_be(in_s, size);
+
+ if ((size == 14) && (version == 0))
+ {
+ in_uint16_be(in_s, code);
+ in_uint16_be(in_s, ok);
+ in_uint16_be(in_s, dummy);
+
+ if (code != 4)
+ {
+ log_message(LOG_LEVEL_ERROR, "Returned cmd code from "
+ "sesman is corrupt");
+ }
+ else
+ {
+ rec = ok; /* here we read the reply from the access control */
+ }
+ }
+ else
+ {
+ log_message(LOG_LEVEL_ERROR, "Corrupt reply size or "
+ "version from sesman: %d", size);
+ }
+ }
+ else
+ {
+ log_message(LOG_LEVEL_ERROR, "No data received from sesman");
+ }
+ }
+ else
+ {
+ log_message(LOG_LEVEL_ERROR, "Timeout when waiting for sesman");
+ }
}
else
{
- log_message(LOG_LEVEL_ERROR, "Corrupt reply size or "
- "version from sesman: %d", size);
+ log_message(LOG_LEVEL_ERROR, "No success sending to sesman");
}
- }
- else
- {
- log_message(LOG_LEVEL_ERROR, "No data received from sesman");
- }
+
+ free_stream(in_s);
+ g_tcp_close(socket);
}
else
{
- log_message(LOG_LEVEL_ERROR, "Timeout when waiting for sesman");
+ log_message(LOG_LEVEL_ERROR, "Failure connecting to socket sesman");
}
- }
- else
- {
- log_message(LOG_LEVEL_ERROR, "No success sending to sesman");
- }
- free_stream(in_s);
- g_tcp_close(socket);
}
else
{
- log_message(LOG_LEVEL_ERROR, "Failure connecting to socket sesman");
+ log_message(LOG_LEVEL_ERROR, "Failure creating socket - for access control");
}
- }
- else
- {
- log_message(LOG_LEVEL_ERROR, "Failure creating socket - for access control");
- }
- return rec;
+
+ return rec;
}
#endif
@@ -1074,1134 +1172,1244 @@ int access_control(char *username, char *password, char *srv)
/* This routine clears all states to make sure that our next login will be
* as expected. If the user does not press ok on the log window and try to
* connect again we must make sure that no previous information is stored.*/
-void cleanup_states(struct xrdp_mm* self)
-{
- if (self != NULL)
- {
- self-> connected_state = 0; /* true if connected to sesman else false */
- self-> sesman_trans = NULL; /* connection to sesman */
- self-> sesman_trans_up = 0; /* true once connected to sesman */
- self-> delete_sesman_trans = 0; /* boolean set when done with sesman connection */
- self-> display = 0; /* 10 for :10.0, 11 for :11.0, etc */
- self-> code = 0; /* 0 Xvnc session 10 X11rdp session */
- self-> sesman_controlled = 0; /* true if this is a sesman session */
- self-> chan_trans = NULL; /* connection to chansrv */
- self-> chan_trans_up = 0; /* true once connected to chansrv */
- self-> delete_chan_trans = 0; /* boolean set when done with channel connection */
- self-> usechansrv = 0; /* true if chansrvport is set in xrdp.ini or using sesman */
- }
+void cleanup_states(struct xrdp_mm *self)
+{
+ if (self != NULL)
+ {
+ self-> connected_state = 0; /* true if connected to sesman else false */
+ self-> sesman_trans = NULL; /* connection to sesman */
+ self-> sesman_trans_up = 0; /* true once connected to sesman */
+ self-> delete_sesman_trans = 0; /* boolean set when done with sesman connection */
+ self-> display = 0; /* 10 for :10.0, 11 for :11.0, etc */
+ self-> code = 0; /* 0 Xvnc session 10 X11rdp session */
+ self-> sesman_controlled = 0; /* true if this is a sesman session */
+ self-> chan_trans = NULL; /* connection to chansrv */
+ self-> chan_trans_up = 0; /* true once connected to chansrv */
+ self-> delete_chan_trans = 0; /* boolean set when done with channel connection */
+ self-> usechansrv = 0; /* true if chansrvport is set in xrdp.ini or using sesman */
+ }
}
/*****************************************************************************/
int APP_CC
-xrdp_mm_connect(struct xrdp_mm* self)
-{
- struct list* names;
- struct list* values;
- int index;
- int count;
- int ok;
- int rv;
- char* name;
- char* value;
- char ip[256];
- char errstr[256];
- char text[256];
- char port[8];
- char chansrvport[256];
+xrdp_mm_connect(struct xrdp_mm *self)
+{
+ struct list *names;
+ struct list *values;
+ int index;
+ int count;
+ int ok;
+ int rv;
+ char *name;
+ char *value;
+ char ip[256];
+ char errstr[256];
+ char text[256];
+ char port[8];
+ char chansrvport[256];
#ifdef ACCESS
- int use_pam_auth = 0;
- char pam_auth_sessionIP[256];
- char pam_auth_password[256];
- char pam_auth_username[256];
- char username[256];
- char password[256];
- username[0] = 0;
- password[0] = 0;
+ int use_pam_auth = 0;
+ char pam_auth_sessionIP[256];
+ char pam_auth_password[256];
+ char pam_auth_username[256];
+ char username[256];
+ char password[256];
+ username[0] = 0;
+ password[0] = 0;
#endif
- /* make sure we start in correct state */
- cleanup_states(self);
- g_memset(ip, 0, sizeof(ip));
- g_memset(errstr, 0, sizeof(errstr));
- g_memset(text, 0, sizeof(text));
- g_memset(port, 0, sizeof(port));
- g_memset(chansrvport, 0, sizeof(chansrvport));
- rv = 0; /* success */
- names = self->login_names;
- values = self->login_values;
- count = names->count;
- for (index = 0; index < count; index++)
- {
- name = (char*)list_get_item(names, index);
- value = (char*)list_get_item(values, index);
- if (g_strcasecmp(name, "ip") == 0)
- {
- g_strncpy(ip, value, 255);
- }
- else if (g_strcasecmp(name, "port") == 0)
- {
- if (g_strcasecmp(value, "-1") == 0)
- {
- self->sesman_controlled = 1;
- }
- }
+ /* make sure we start in correct state */
+ cleanup_states(self);
+ g_memset(ip, 0, sizeof(ip));
+ g_memset(errstr, 0, sizeof(errstr));
+ g_memset(text, 0, sizeof(text));
+ g_memset(port, 0, sizeof(port));
+ g_memset(chansrvport, 0, sizeof(chansrvport));
+ rv = 0; /* success */
+ names = self->login_names;
+ values = self->login_values;
+ count = names->count;
+
+ for (index = 0; index < count; index++)
+ {
+ name = (char *)list_get_item(names, index);
+ value = (char *)list_get_item(values, index);
+
+ if (g_strcasecmp(name, "ip") == 0)
+ {
+ g_strncpy(ip, value, 255);
+ }
+ else if (g_strcasecmp(name, "port") == 0)
+ {
+ if (g_strcasecmp(value, "-1") == 0)
+ {
+ self->sesman_controlled = 1;
+ }
+ }
+
#ifdef ACCESS
- else if (g_strcasecmp(name, "pamusername") == 0)
- {
- use_pam_auth = 1;
- g_strncpy(pam_auth_username, value, 255);
- }
- else if (g_strcasecmp(name, "pamsessionmng") == 0)
- {
- g_strncpy(pam_auth_sessionIP, value, 255);
- }
- else if (g_strcasecmp(name, "pampassword") == 0)
- {
- g_strncpy(pam_auth_password, value, 255);
- }
- else if (g_strcasecmp(name, "password") == 0)
- {
- g_strncpy(password, value, 255);
- }
- else if (g_strcasecmp(name, "username") == 0)
- {
- g_strncpy(username, value, 255);
- }
+ else if (g_strcasecmp(name, "pamusername") == 0)
+ {
+ use_pam_auth = 1;
+ g_strncpy(pam_auth_username, value, 255);
+ }
+ else if (g_strcasecmp(name, "pamsessionmng") == 0)
+ {
+ g_strncpy(pam_auth_sessionIP, value, 255);
+ }
+ else if (g_strcasecmp(name, "pampassword") == 0)
+ {
+ g_strncpy(pam_auth_password, value, 255);
+ }
+ else if (g_strcasecmp(name, "password") == 0)
+ {
+ g_strncpy(password, value, 255);
+ }
+ else if (g_strcasecmp(name, "username") == 0)
+ {
+ g_strncpy(username, value, 255);
+ }
+
#endif
- else if (g_strcasecmp(name, "chansrvport") == 0)
- {
- g_strncpy(chansrvport, value, 255);
- self->usechansrv = 1;
+ else if (g_strcasecmp(name, "chansrvport") == 0)
+ {
+ g_strncpy(chansrvport, value, 255);
+ self->usechansrv = 1;
+ }
}
- }
+
#ifdef ACCESS
- if (use_pam_auth)
- {
- int reply;
- char replytxt[80];
- char replymessage[4][80] = {"Ok","Sesman connect failure","User or password error","Privilege group error"};
- xrdp_wm_log_msg(self->wm, "Please wait, we now perform access control...");
- /* g_writeln("we use pam modules to check if we can approve this user"); */
- if (!g_strncmp(pam_auth_username, "same", 255))
- {
- log_message(LOG_LEVEL_DEBUG, "pamusername copied from username - same: %s", username);
- g_strncpy(pam_auth_username,username, 255);
- }
- if (!g_strncmp(pam_auth_password, "same", 255))
- {
- log_message(LOG_LEVEL_DEBUG,"pam_auth_password copied from username - same: %s", password);
- g_strncpy(pam_auth_password, password, 255);
- }
- /* access_control return 0 on success */
- reply = access_control(pam_auth_username, pam_auth_password, pam_auth_sessionIP);
- if (reply >= 0 && reply < 4)
+
+ if (use_pam_auth)
{
- g_sprintf(replytxt,"Reply from access control: %s", replymessage[reply]);
+ int reply;
+ char replytxt[80];
+ char replymessage[4][80] = {"Ok", "Sesman connect failure", "User or password error", "Privilege group error"};
+ xrdp_wm_log_msg(self->wm, "Please wait, we now perform access control...");
+
+ /* g_writeln("we use pam modules to check if we can approve this user"); */
+ if (!g_strncmp(pam_auth_username, "same", 255))
+ {
+ log_message(LOG_LEVEL_DEBUG, "pamusername copied from username - same: %s", username);
+ g_strncpy(pam_auth_username, username, 255);
+ }
+
+ if (!g_strncmp(pam_auth_password, "same", 255))
+ {
+ log_message(LOG_LEVEL_DEBUG, "pam_auth_password copied from username - same: %s", password);
+ g_strncpy(pam_auth_password, password, 255);
+ }
+
+ /* access_control return 0 on success */
+ reply = access_control(pam_auth_username, pam_auth_password, pam_auth_sessionIP);
+
+ if (reply >= 0 && reply < 4)
+ {
+ g_sprintf(replytxt, "Reply from access control: %s", replymessage[reply]);
+ }
+ else
+ {
+ g_sprintf(replytxt, "Reply from access control undefined");
+ }
+
+ xrdp_wm_log_msg(self->wm, replytxt);
+ log_message(LOG_LEVEL_INFO, replytxt);
+
+ if (reply != 0)
+ {
+ rv = 1;
+ return rv;
+ }
}
- else
+
+#endif
+
+ if (self->sesman_controlled)
{
- g_sprintf(replytxt,"Reply from access control undefined");
+ ok = 0;
+ trans_delete(self->sesman_trans);
+ self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
+ xrdp_mm_get_sesman_port(port, sizeof(port));
+ g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port);
+ xrdp_wm_log_msg(self->wm, text);
+ /* xrdp_mm_sesman_data_in is the callback that is called when data arrives */
+ self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in;
+ self->sesman_trans->header_size = 8;
+ self->sesman_trans->callback_data = self;
+
+ /* try to connect up to 4 times */
+ for (index = 0; index < 4; index++)
+ {
+ if (trans_connect(self->sesman_trans, ip, port, 3000) == 0)
+ {
+ self->sesman_trans_up = 1;
+ ok = 1;
+ break;
+ }
+
+ g_sleep(1000);
+ g_writeln("xrdp_mm_connect: connect failed "
+ "trying again...");
+ }
+
+ if (ok)
+ {
+ /* fully connect */
+ xrdp_wm_log_msg(self->wm, "sesman connect ok");
+ self->connected_state = 1;
+ rv = xrdp_mm_send_login(self);
+ }
+ else
+ {
+ g_snprintf(errstr, 255, "Failure to connect to sesman: %s port: %s",
+ ip, port);
+ xrdp_wm_log_msg(self->wm, errstr);
+ trans_delete(self->sesman_trans);
+ self->sesman_trans = 0;
+ self->sesman_trans_up = 0;
+ rv = 1;
+ }
}
- xrdp_wm_log_msg(self->wm,replytxt);
- log_message(LOG_LEVEL_INFO,replytxt);
- if (reply != 0)
+ else /* no sesman */
{
- rv = 1;
- return rv;
+ if (xrdp_mm_setup_mod1(self) == 0)
+ {
+ if (xrdp_mm_setup_mod2(self) == 0)
+ {
+ xrdp_wm_set_login_mode(self->wm, 10);
+ rv = 0; /*sucess*/
+ }
+ else
+ {
+ /* connect error */
+ g_snprintf(errstr, 255, "Failure to connect to: %s", ip);
+ xrdp_wm_log_msg(self->wm, errstr);
+ rv = 1; /* failure */
+ }
+ }
+ else
+ {
+ g_writeln("Failure setting up module");
+ }
+
+ if (self->wm->login_mode != 10)
+ {
+ xrdp_wm_set_login_mode(self->wm, 11);
+ xrdp_mm_module_cleanup(self);
+ rv = 1; /* failure */
+ }
}
- }
-#endif
- if (self->sesman_controlled)
- {
- ok = 0;
- trans_delete(self->sesman_trans);
- self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
- xrdp_mm_get_sesman_port(port, sizeof(port));
- g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port);
- xrdp_wm_log_msg(self->wm, text);
- /* xrdp_mm_sesman_data_in is the callback that is called when data arrives */
- self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in;
- self->sesman_trans->header_size = 8;
- self->sesman_trans->callback_data = self;
- /* try to connect up to 4 times */
- for (index = 0; index < 4; index++)
+
+ if ((self->wm->login_mode == 10) && (self->sesman_controlled == 0) &&
+ (self->usechansrv != 0))
{
- if (trans_connect(self->sesman_trans, ip, port, 3000) == 0)
- {
- self->sesman_trans_up = 1;
- ok = 1;
- break;
- }
- g_sleep(1000);
- g_writeln("xrdp_mm_connect: connect failed "
- "trying again...");
+ /* if sesman controlled, this will connect later */
+ xrdp_mm_connect_chansrv(self, "", chansrvport);
}
- if (ok)
+
+ g_writeln("returnvalue from xrdp_mm_connect %d", rv);
+
+ return rv;
+}
+
+/*****************************************************************************/
+int APP_CC
+xrdp_mm_get_wait_objs(struct xrdp_mm *self,
+ tbus *read_objs, int *rcount,
+ tbus *write_objs, int *wcount, int *timeout)
+{
+ int rv = 0;
+
+ if (self == 0)
{
- /* fully connect */
- xrdp_wm_log_msg(self->wm, "sesman connect ok");
- self->connected_state = 1;
- rv = xrdp_mm_send_login(self);
+ return 0;
}
- else
+
+ rv = 0;
+
+ if ((self->sesman_trans != 0) && self->sesman_trans_up)
{
- g_snprintf(errstr, 255, "Failure to connect to sesman: %s port: %s",
- ip, port);
- xrdp_wm_log_msg(self->wm, errstr);
- trans_delete(self->sesman_trans);
- self->sesman_trans = 0;
- self->sesman_trans_up = 0;
- rv = 1;
- }
- }
- else /* no sesman */
- {
- if (xrdp_mm_setup_mod1(self) == 0)
- {
- if (xrdp_mm_setup_mod2(self) == 0)
- {
- xrdp_wm_set_login_mode(self->wm, 10);
- rv = 0; /*sucess*/
- }
- else
- {
- /* connect error */
- g_snprintf(errstr, 255, "Failure to connect to: %s", ip);
- xrdp_wm_log_msg(self->wm, errstr);
- rv = 1; /* failure */
- }
+ trans_get_wait_objs(self->sesman_trans, read_objs, rcount);
}
- else
+
+ if ((self->chan_trans != 0) && self->chan_trans_up)
{
- g_writeln("Failure setting up module");
+ trans_get_wait_objs(self->chan_trans, read_objs, rcount);
}
- if (self->wm->login_mode != 10)
+
+ if (self->mod != 0)
{
- xrdp_wm_set_login_mode(self->wm, 11);
- xrdp_mm_module_cleanup(self);
- rv = 1; /* failure */
+ if (self->mod->mod_get_wait_objs != 0)
+ {
+ rv = self->mod->mod_get_wait_objs(self->mod, read_objs, rcount,
+ write_objs, wcount, timeout);
+ }
}
- }
- if ((self->wm->login_mode == 10) && (self->sesman_controlled == 0) &&
- (self->usechansrv != 0))
- {
- /* if sesman controlled, this will connect later */
- xrdp_mm_connect_chansrv(self, "", chansrvport);
- }
- g_writeln("returnvalue from xrdp_mm_connect %d", rv);
-
- return rv;
+ return rv;
}
/*****************************************************************************/
int APP_CC
-xrdp_mm_get_wait_objs(struct xrdp_mm* self,
- tbus* read_objs, int* rcount,
- tbus* write_objs, int* wcount, int* timeout)
+xrdp_mm_check_wait_objs(struct xrdp_mm *self)
{
- int rv = 0;
+ int rv;
- if (self == 0)
- {
- return 0;
- }
- rv = 0;
- if ((self->sesman_trans != 0) && self->sesman_trans_up)
- {
- trans_get_wait_objs(self->sesman_trans, read_objs, rcount);
- }
- if ((self->chan_trans != 0) && self->chan_trans_up)
- {
- trans_get_wait_objs(self->chan_trans, read_objs, rcount);
- }
- if (self->mod != 0)
- {
- if (self->mod->mod_get_wait_objs != 0)
+ if (self == 0)
{
- rv = self->mod->mod_get_wait_objs(self->mod, read_objs, rcount,
- write_objs, wcount, timeout);
+ return 0;
}
- }
- return rv;
-}
+ rv = 0;
-/*****************************************************************************/
-int APP_CC
-xrdp_mm_check_wait_objs(struct xrdp_mm* self)
-{
- int rv;
+ if ((self->sesman_trans != 0) && self->sesman_trans_up)
+ {
+ if (trans_check_wait_objs(self->sesman_trans) != 0)
+ {
+ self->delete_sesman_trans = 1;
+ }
+ }
- if (self == 0)
- {
- return 0;
- }
- rv = 0;
- if ((self->sesman_trans != 0) && self->sesman_trans_up)
- {
- if (trans_check_wait_objs(self->sesman_trans) != 0)
+ if ((self->chan_trans != 0) && self->chan_trans_up)
+ {
+ if (trans_check_wait_objs(self->chan_trans) != 0)
+ {
+ self->delete_chan_trans = 1;
+ }
+ }
+
+ if (self->mod != 0)
{
- self->delete_sesman_trans = 1;
+ if (self->mod->mod_check_wait_objs != 0)
+ {
+ rv = self->mod->mod_check_wait_objs(self->mod);
+ }
}
- }
- if ((self->chan_trans != 0) && self->chan_trans_up)
- {
- if (trans_check_wait_objs(self->chan_trans) != 0)
+
+ if (self->delete_sesman_trans)
{
- self->delete_chan_trans = 1;
+ trans_delete(self->sesman_trans);
+ self->sesman_trans = 0;
+ self->sesman_trans_up = 0;
+ self->delete_sesman_trans = 0;
}
- }
- if (self->mod != 0)
- {
- if (self->mod->mod_check_wait_objs != 0)
+
+ if (self->delete_chan_trans)
{
- rv = self->mod->mod_check_wait_objs(self->mod);
+ trans_delete(self->chan_trans);
+ self->chan_trans = 0;
+ self->chan_trans_up = 0;
+ self->delete_chan_trans = 0;
}
- }
- if (self->delete_sesman_trans)
- {
- trans_delete(self->sesman_trans);
- self->sesman_trans = 0;
- self->sesman_trans_up = 0;
- self->delete_sesman_trans = 0;
- }
- if (self->delete_chan_trans)
- {
- trans_delete(self->chan_trans);
- self->chan_trans = 0;
- self->chan_trans_up = 0;
- self->delete_chan_trans = 0;
- }
- return rv;
+ return rv;
}
#if 0
/*****************************************************************************/
-struct xrdp_painter* APP_CC
-get_painter(struct xrdp_mod* mod)
+struct xrdp_painter *APP_CC
+get_painter(struct xrdp_mod *mod)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
- wm = (struct xrdp_wm*)(mod->wm);
- p = xrdp_painter_create(wm, wm->session);
- mod->painter = (tintptr)p;
- }
- return p;
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ wm = (struct xrdp_wm *)(mod->wm);
+ p = xrdp_painter_create(wm, wm->session);
+ mod->painter = (tintptr)p;
+ }
+
+ return p;
}
#endif
/*****************************************************************************/
int DEFAULT_CC
-server_begin_update(struct xrdp_mod* mod)
+server_begin_update(struct xrdp_mod *mod)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
- wm = (struct xrdp_wm*)(mod->wm);
- p = xrdp_painter_create(wm, wm->session);
- xrdp_painter_begin_update(p);
- mod->painter = (long)p;
- return 0;
+ wm = (struct xrdp_wm *)(mod->wm);
+ p = xrdp_painter_create(wm, wm->session);
+ xrdp_painter_begin_update(p);
+ mod->painter = (long)p;
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_end_update(struct xrdp_mod* mod)
+server_end_update(struct xrdp_mod *mod)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ xrdp_painter_end_update(p);
+ xrdp_painter_delete(p);
+ mod->painter = 0;
return 0;
- }
- xrdp_painter_end_update(p);
- xrdp_painter_delete(p);
- mod->painter = 0;
- return 0;
}
/*****************************************************************************/
/* got bell signal... try to send to client */
int DEFAULT_CC
-server_bell_trigger(struct xrdp_mod* mod)
+server_bell_trigger(struct xrdp_mod *mod)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- xrdp_wm_send_bell(wm);
- return 0;
+ wm = (struct xrdp_wm *)(mod->wm);
+ xrdp_wm_send_bell(wm);
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_fill_rect(struct xrdp_mod* mod, int x, int y, int cx, int cy)
+server_fill_rect(struct xrdp_mod *mod, int x, int y, int cx, int cy)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ wm = (struct xrdp_wm *)(mod->wm);
+ xrdp_painter_fill_rect(p, wm->target_surface, x, y, cx, cy);
return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- xrdp_painter_fill_rect(p, wm->target_surface, x, y, cx, cy);
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_screen_blt(struct xrdp_mod* mod, int x, int y, int cx, int cy,
+server_screen_blt(struct xrdp_mod *mod, int x, int y, int cx, int cy,
int srcx, int srcy)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ wm = (struct xrdp_wm *)(mod->wm);
+ p->rop = 0xcc;
+ xrdp_painter_copy(p, wm->screen, wm->target_surface, x, y, cx, cy, srcx, srcy);
return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- p->rop = 0xcc;
- xrdp_painter_copy(p, wm->screen, wm->target_surface, x, y, cx, cy, srcx, srcy);
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_paint_rect(struct xrdp_mod* mod, int x, int y, int cx, int cy,
- char* data, int width, int height, int srcx, int srcy)
+server_paint_rect(struct xrdp_mod *mod, int x, int y, int cx, int cy,
+ char *data, int width, int height, int srcx, int srcy)
{
- struct xrdp_wm* wm;
- struct xrdp_bitmap* b;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_bitmap *b;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ wm = (struct xrdp_wm *)(mod->wm);
+ b = xrdp_bitmap_create_with_data(width, height, wm->screen->bpp, data, wm);
+ xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);
+ xrdp_bitmap_delete(b);
return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- b = xrdp_bitmap_create_with_data(width, height, wm->screen->bpp, data, wm);
- xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);
- xrdp_bitmap_delete(b);
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_pointer(struct xrdp_mod* mod, int x, int y,
- char* data, char* mask)
+server_set_pointer(struct xrdp_mod *mod, int x, int y,
+ char *data, char *mask)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- xrdp_wm_pointer(wm, data, mask, x, y);
- return 0;
+ wm = (struct xrdp_wm *)(mod->wm);
+ xrdp_wm_pointer(wm, data, mask, x, y);
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_palette(struct xrdp_mod* mod, int* palette)
+server_palette(struct xrdp_mod *mod, int *palette)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
+
+ wm = (struct xrdp_wm *)(mod->wm);
- wm = (struct xrdp_wm*)(mod->wm);
- if (g_memcmp(wm->palette, palette, 255 * sizeof(int)) != 0)
- {
- g_memcpy(wm->palette, palette, 256 * sizeof(int));
- xrdp_wm_send_palette(wm);
- }
- return 0;
+ if (g_memcmp(wm->palette, palette, 255 * sizeof(int)) != 0)
+ {
+ g_memcpy(wm->palette, palette, 256 * sizeof(int));
+ xrdp_wm_send_palette(wm);
+ }
+
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_msg(struct xrdp_mod* mod, char* msg, int code)
+server_msg(struct xrdp_mod *mod, char *msg, int code)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- if (code == 1)
- {
- g_writeln(msg);
- return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- return xrdp_wm_log_msg(wm, msg);
+ if (code == 1)
+ {
+ g_writeln(msg);
+ return 0;
+ }
+
+ wm = (struct xrdp_wm *)(mod->wm);
+ return xrdp_wm_log_msg(wm, msg);
}
/*****************************************************************************/
int DEFAULT_CC
-server_is_term(struct xrdp_mod* mod)
+server_is_term(struct xrdp_mod *mod)
{
- return g_is_term();
+ return g_is_term();
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_clip(struct xrdp_mod* mod, int x, int y, int cx, int cy)
+server_set_clip(struct xrdp_mod *mod, int x, int y, int cx, int cy)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
- return 0;
- }
- return xrdp_painter_set_clip(p, x, y, cx, cy);
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ return xrdp_painter_set_clip(p, x, y, cx, cy);
}
/*****************************************************************************/
int DEFAULT_CC
-server_reset_clip(struct xrdp_mod* mod)
+server_reset_clip(struct xrdp_mod *mod)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
- return 0;
- }
- return xrdp_painter_clr_clip(p);
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ return xrdp_painter_clr_clip(p);
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_fgcolor(struct xrdp_mod* mod, int fgcolor)
+server_set_fgcolor(struct xrdp_mod *mod, int fgcolor)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ p->fg_color = fgcolor;
+ p->pen.color = p->fg_color;
return 0;
- }
- p->fg_color = fgcolor;
- p->pen.color = p->fg_color;
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_bgcolor(struct xrdp_mod* mod, int bgcolor)
+server_set_bgcolor(struct xrdp_mod *mod, int bgcolor)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ p->bg_color = bgcolor;
return 0;
- }
- p->bg_color = bgcolor;
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_opcode(struct xrdp_mod* mod, int opcode)
+server_set_opcode(struct xrdp_mod *mod, int opcode)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ p->rop = opcode;
return 0;
- }
- p->rop = opcode;
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_mixmode(struct xrdp_mod* mod, int mixmode)
+server_set_mixmode(struct xrdp_mod *mod, int mixmode)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ p->mix_mode = mixmode;
return 0;
- }
- p->mix_mode = mixmode;
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_brush(struct xrdp_mod* mod, int x_orgin, int y_orgin,
- int style, char* pattern)
+server_set_brush(struct xrdp_mod *mod, int x_orgin, int y_orgin,
+ int style, char *pattern)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ p->brush.x_orgin = x_orgin;
+ p->brush.y_orgin = y_orgin;
+ p->brush.style = style;
+ g_memcpy(p->brush.pattern, pattern, 8);
return 0;
- }
- p->brush.x_orgin = x_orgin;
- p->brush.y_orgin = y_orgin;
- p->brush.style = style;
- g_memcpy(p->brush.pattern, pattern, 8);
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_pen(struct xrdp_mod* mod, int style, int width)
+server_set_pen(struct xrdp_mod *mod, int style, int width)
{
- struct xrdp_painter* p;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ p->pen.style = style;
+ p->pen.width = width;
return 0;
- }
- p->pen.style = style;
- p->pen.width = width;
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_draw_line(struct xrdp_mod* mod, int x1, int y1, int x2, int y2)
+server_draw_line(struct xrdp_mod *mod, int x1, int y1, int x2, int y2)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
- return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- return xrdp_painter_line(p, wm->target_surface, x1, y1, x2, y2);
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ wm = (struct xrdp_wm *)(mod->wm);
+ return xrdp_painter_line(p, wm->target_surface, x1, y1, x2, y2);
}
/*****************************************************************************/
int DEFAULT_CC
-server_add_char(struct xrdp_mod* mod, int font, int charactor,
+server_add_char(struct xrdp_mod *mod, int font, int charactor,
int offset, int baseline,
- int width, int height, char* data)
+ int width, int height, char *data)
{
- struct xrdp_font_char fi;
+ struct xrdp_font_char fi;
- fi.offset = offset;
- fi.baseline = baseline;
- fi.width = width;
- fi.height = height;
- fi.incby = 0;
- fi.data = data;
- return libxrdp_orders_send_font(((struct xrdp_wm*)mod->wm)->session,
- &fi, font, charactor);
+ fi.offset = offset;
+ fi.baseline = baseline;
+ fi.width = width;
+ fi.height = height;
+ fi.incby = 0;
+ fi.data = data;
+ return libxrdp_orders_send_font(((struct xrdp_wm *)mod->wm)->session,
+ &fi, font, charactor);
}
/*****************************************************************************/
int DEFAULT_CC
-server_draw_text(struct xrdp_mod* mod, int font,
+server_draw_text(struct xrdp_mod *mod, int font,
int flags, int mixmode, int clip_left, int clip_top,
int clip_right, int clip_bottom,
int box_left, int box_top,
int box_right, int box_bottom,
- int x, int y, char* data, int data_len)
+ int x, int y, char *data, int data_len)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
- return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- return xrdp_painter_draw_text2(p, wm->target_surface, font, flags,
- mixmode, clip_left, clip_top,
- clip_right, clip_bottom,
- box_left, box_top,
- box_right, box_bottom,
- x, y, data, data_len);
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ wm = (struct xrdp_wm *)(mod->wm);
+ return xrdp_painter_draw_text2(p, wm->target_surface, font, flags,
+ mixmode, clip_left, clip_top,
+ clip_right, clip_bottom,
+ box_left, box_top,
+ box_right, box_bottom,
+ x, y, data, data_len);
}
/*****************************************************************************/
int DEFAULT_CC
-server_reset(struct xrdp_mod* mod, int width, int height, int bpp)
-{
- struct xrdp_wm* wm;
-
- wm = (struct xrdp_wm*)(mod->wm);
- if (wm->client_info == 0)
- {
- return 1;
- }
- /* older client can't resize */
- if (wm->client_info->build <= 419)
- {
- return 0;
- }
- /* if same, don't need to do anything */
- if (wm->client_info->width == width &&
- wm->client_info->height == height &&
- wm->client_info->bpp == bpp)
- {
+server_reset(struct xrdp_mod *mod, int width, int height, int bpp)
+{
+ struct xrdp_wm *wm;
+
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (wm->client_info == 0)
+ {
+ return 1;
+ }
+
+ /* older client can't resize */
+ if (wm->client_info->build <= 419)
+ {
+ return 0;
+ }
+
+ /* if same, don't need to do anything */
+ if (wm->client_info->width == width &&
+ wm->client_info->height == height &&
+ wm->client_info->bpp == bpp)
+ {
+ return 0;
+ }
+
+ /* reset lib, client_info gets updated in libxrdp_reset */
+ if (libxrdp_reset(wm->session, width, height, bpp) != 0)
+ {
+ return 1;
+ }
+
+ /* reset cache */
+ xrdp_cache_reset(wm->cache, wm->client_info);
+ /* resize the main window */
+ xrdp_bitmap_resize(wm->screen, wm->client_info->width,
+ wm->client_info->height);
+ /* load some stuff */
+ xrdp_wm_load_static_colors_plus(wm, 0);
+ xrdp_wm_load_static_pointers(wm);
return 0;
- }
- /* reset lib, client_info gets updated in libxrdp_reset */
- if (libxrdp_reset(wm->session, width, height, bpp) != 0)
- {
- return 1;
- }
- /* reset cache */
- xrdp_cache_reset(wm->cache, wm->client_info);
- /* resize the main window */
- xrdp_bitmap_resize(wm->screen, wm->client_info->width,
- wm->client_info->height);
- /* load some stuff */
- xrdp_wm_load_static_colors_plus(wm, 0);
- xrdp_wm_load_static_pointers(wm);
- return 0;
}
/* read the channel section of the ini file into lists
* return 1 on success 0 on failure */
-int read_allowed_channel_names(struct list* names, struct list* values)
-{
- int fd;
- int ret = 0;
- char cfg_file[256];
- int pos;
- g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
- fd = g_file_open(cfg_file);
- if (fd > 0)
- {
- names->auto_free = 1;
- values->auto_free = 1;
- pos = 0;
- /* all values in this section can be valid channel names */
- if (file_read_section(fd, "channels", names, values) == 0)
- {
- ret = 1;
- }
- else
+int read_allowed_channel_names(struct list *names, struct list *values)
+{
+ int fd;
+ int ret = 0;
+ char cfg_file[256];
+ int pos;
+ g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+ fd = g_file_open(cfg_file);
+
+ if (fd > 0)
{
- g_writeln("Failure reading channel section of configuration");
+ names->auto_free = 1;
+ values->auto_free = 1;
+ pos = 0;
+
+ /* all values in this section can be valid channel names */
+ if (file_read_section(fd, "channels", names, values) == 0)
+ {
+ ret = 1;
+ }
+ else
+ {
+ g_writeln("Failure reading channel section of configuration");
+ }
+
+ g_file_close(fd);
+ return ret;
}
- g_file_close(fd);
- return ret;
- }
}
/* internal function return 1 if name is in list of channels
* and if the value is allowed */
int DEFAULT_CC
-is_name_in_lists(char* inName, struct list* names, struct list* values)
-{
- int reply = 0; /*means not in the list*/
- int index;
- char* val;
- char* name;
- for (index = 0; index < names->count; index++)
- {
- name = (char*)list_get_item(names, index);
- if (name != 0)
- {
- /* ex rdpdr ;rdpsnd ; drdynvc ; cliprdr */
- if (!g_strncmp(name, inName, MAX_CHANNEL_NAME))
- {
- val = (char*)list_get_item(values, index);
- if ((g_strcasecmp(val, "yes") == 0) ||
- (g_strcasecmp(val, "on") == 0) ||
- (g_strcasecmp(val, "true") == 0) ||
- (g_atoi(val) != 0))
- {
- reply = 1;
- }
- else
+is_name_in_lists(char *inName, struct list *names, struct list *values)
+{
+ int reply = 0; /*means not in the list*/
+ int index;
+ char *val;
+ char *name;
+
+ for (index = 0; index < names->count; index++)
+ {
+ name = (char *)list_get_item(names, index);
+
+ if (name != 0)
{
- g_writeln("This channel is disabled: %s", name);
+ /* ex rdpdr ;rdpsnd ; drdynvc ; cliprdr */
+ if (!g_strncmp(name, inName, MAX_CHANNEL_NAME))
+ {
+ val = (char *)list_get_item(values, index);
+
+ if ((g_strcasecmp(val, "yes") == 0) ||
+ (g_strcasecmp(val, "on") == 0) ||
+ (g_strcasecmp(val, "true") == 0) ||
+ (g_atoi(val) != 0))
+ {
+ reply = 1;
+ }
+ else
+ {
+ g_writeln("This channel is disabled: %s", name);
+ }
+
+ break; /* stop loop - item found*/
+ }
}
- break; /* stop loop - item found*/
- }
}
- }
- return reply;
+
+ return reply;
}
/* internal function only used once per session
* creates the list of allowed channels and store the information
* in wm struct */
-void init_channel_allowed(struct xrdp_wm* wm)
-{
- int error;
- int i;
- char channelname[MAX_CHANNEL_NAME];
- int index = 0;
- int allowindex = 0;
- struct list* names;
- struct list* values;
- /* first reset allowedchannels */
- for (i = 0; i < MAX_NR_CHANNELS; i++)
- {
- /* 0 is a valid channel so we use -1 to mark the index as unused */
- wm->allowedchannels[i] = -1;
- }
- names = list_create();
- values = list_create();
- if (read_allowed_channel_names(names, values))
- {
- do
- {
- /* libxrdp_query_channel return 1 on error*/
- error = libxrdp_query_channel(wm->session, index, channelname,NULL);
- if (error == 0)
- {
- /* examples of channel names: rdpdr ; rdpsnd ; drdynvc ; cliprdr */
- if (is_name_in_lists(channelname, names, values))
- {
- g_writeln("The following channel is allowed: %s", channelname);
- wm->allowedchannels[allowindex] = index;
- allowindex++;
- if (allowindex >= MAX_NR_CHANNELS)
- {
- g_writeln("Programming error in is_channel_allowed");
- error = 1; /* end loop */
- }
- }
- else
+void init_channel_allowed(struct xrdp_wm *wm)
+{
+ int error;
+ int i;
+ char channelname[MAX_CHANNEL_NAME];
+ int index = 0;
+ int allowindex = 0;
+ struct list *names;
+ struct list *values;
+
+ /* first reset allowedchannels */
+ for (i = 0; i < MAX_NR_CHANNELS; i++)
+ {
+ /* 0 is a valid channel so we use -1 to mark the index as unused */
+ wm->allowedchannels[i] = -1;
+ }
+
+ names = list_create();
+ values = list_create();
+
+ if (read_allowed_channel_names(names, values))
+ {
+ do
{
- g_writeln("The following channel is not allowed: %s",channelname);
+ /* libxrdp_query_channel return 1 on error*/
+ error = libxrdp_query_channel(wm->session, index, channelname, NULL);
+
+ if (error == 0)
+ {
+ /* examples of channel names: rdpdr ; rdpsnd ; drdynvc ; cliprdr */
+ if (is_name_in_lists(channelname, names, values))
+ {
+ g_writeln("The following channel is allowed: %s", channelname);
+ wm->allowedchannels[allowindex] = index;
+ allowindex++;
+
+ if (allowindex >= MAX_NR_CHANNELS)
+ {
+ g_writeln("Programming error in is_channel_allowed");
+ error = 1; /* end loop */
+ }
+ }
+ else
+ {
+ g_writeln("The following channel is not allowed: %s", channelname);
+ }
+
+ index++;
+ }
}
- index++;
- }
- } while ((error == 0) && (index < MAX_NR_CHANNELS));
- }
- else
- {
- g_writeln("Error reading channel section in inifile");
- }
- list_delete(names);
- list_delete(values);
+ while ((error == 0) && (index < MAX_NR_CHANNELS));
+ }
+ else
+ {
+ g_writeln("Error reading channel section in inifile");
+ }
+
+ list_delete(names);
+ list_delete(values);
}
/*****************************************************************************/
/* This function returns 1 if the channelID is allowed by rule set
* returns 0 if not allowed */
-int DEFAULT_CC is_channel_allowed(struct xrdp_wm* wm, int channel_id)
+int DEFAULT_CC is_channel_allowed(struct xrdp_wm *wm, int channel_id)
{
- int i;
- int reply = 0; /* not allowed */
- /* The first time each client is using this function we have to
- * define the list of allowed channels */
- if (wm->allowedinitialized == 0)
- {
- init_channel_allowed(wm);
- g_writeln("allow channel list initialized");
- wm->allowedinitialized = 1;
- }
- for(i = 0; i < MAX_NR_CHANNELS; i++)
- {
- if (channel_id == wm->allowedchannels[i])
+ int i;
+ int reply = 0; /* not allowed */
+
+ /* The first time each client is using this function we have to
+ * define the list of allowed channels */
+ if (wm->allowedinitialized == 0)
{
- /*g_writeln("Channel allowed: %d",channel_id);*/
- reply = 1; /*channel allowed*/
- break;
+ init_channel_allowed(wm);
+ g_writeln("allow channel list initialized");
+ wm->allowedinitialized = 1;
}
- else if (wm->allowedchannels[i] == -1)
+
+ for (i = 0; i < MAX_NR_CHANNELS; i++)
{
- /* We are in the unused space of the allowedchannels list
- * We can end the loop */
- break;
+ if (channel_id == wm->allowedchannels[i])
+ {
+ /*g_writeln("Channel allowed: %d",channel_id);*/
+ reply = 1; /*channel allowed*/
+ break;
+ }
+ else if (wm->allowedchannels[i] == -1)
+ {
+ /* We are in the unused space of the allowedchannels list
+ * We can end the loop */
+ break;
+ }
}
- }
- /*if (reply == 0)
- {
- g_writeln("This channel is NOT allowed: %d",channel_id) ;
- }*/
- return reply;
+
+ /*if (reply == 0)
+ {
+ g_writeln("This channel is NOT allowed: %d",channel_id) ;
+ }*/
+ return reply;
}
/*****************************************************************************/
/*return 0 if the index is not found*/
int DEFAULT_CC
-server_query_channel(struct xrdp_mod* mod, int index, char* channel_name,
- int* channel_flags)
+server_query_channel(struct xrdp_mod *mod, int index, char *channel_name,
+ int *channel_flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
+
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (wm->mm->usechansrv)
+ {
+ return 1;
+ }
- wm = (struct xrdp_wm*)(mod->wm);
- if (wm->mm->usechansrv)
- {
- return 1;
- }
- return libxrdp_query_channel(wm->session, index, channel_name,
- channel_flags);
+ return libxrdp_query_channel(wm->session, index, channel_name,
+ channel_flags);
}
/*****************************************************************************/
/* returns -1 on error */
int DEFAULT_CC
-server_get_channel_id(struct xrdp_mod* mod, char* name)
+server_get_channel_id(struct xrdp_mod *mod, char *name)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
+
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (wm->mm->usechansrv)
+ {
+ return -1;
+ }
- wm = (struct xrdp_wm*)(mod->wm);
- if (wm->mm->usechansrv)
- {
- return -1;
- }
- return libxrdp_get_channel_id(wm->session, name);
+ return libxrdp_get_channel_id(wm->session, name);
}
/*****************************************************************************/
int DEFAULT_CC
-server_send_to_channel(struct xrdp_mod* mod, int channel_id,
- char* data, int data_len,
+server_send_to_channel(struct xrdp_mod *mod, int channel_id,
+ char *data, int data_len,
int total_data_len, int flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- if (is_channel_allowed(wm, channel_id))
- {
- if (wm->mm->usechansrv)
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (is_channel_allowed(wm, channel_id))
+ {
+ if (wm->mm->usechansrv)
+ {
+ return 1;
+ }
+
+ return libxrdp_send_to_channel(wm->session, channel_id, data, data_len,
+ total_data_len, flags);
+ }
+ else
{
- return 1;
+ return 1;
}
- return libxrdp_send_to_channel(wm->session, channel_id, data, data_len,
- total_data_len, flags);
- }
- else
- {
- return 1;
- }
}
/*****************************************************************************/
int DEFAULT_CC
-server_create_os_surface(struct xrdp_mod* mod, int rdpindex,
+server_create_os_surface(struct xrdp_mod *mod, int rdpindex,
int width, int height)
{
- struct xrdp_wm* wm;
- struct xrdp_bitmap* bitmap;
- int error;
+ struct xrdp_wm *wm;
+ struct xrdp_bitmap *bitmap;
+ int error;
- wm = (struct xrdp_wm*)(mod->wm);
- bitmap = xrdp_bitmap_create(width, height, wm->screen->bpp,
- WND_TYPE_OFFSCREEN, wm);
- error = xrdp_cache_add_os_bitmap(wm->cache, bitmap, rdpindex);
- if (error != 0)
- {
- g_writeln("server_create_os_surface: xrdp_cache_add_os_bitmap failed");
- return 1;
- }
- bitmap->item_index = rdpindex;
- bitmap->id = rdpindex;
- return 0;
+ wm = (struct xrdp_wm *)(mod->wm);
+ bitmap = xrdp_bitmap_create(width, height, wm->screen->bpp,
+ WND_TYPE_OFFSCREEN, wm);
+ error = xrdp_cache_add_os_bitmap(wm->cache, bitmap, rdpindex);
+
+ if (error != 0)
+ {
+ g_writeln("server_create_os_surface: xrdp_cache_add_os_bitmap failed");
+ return 1;
+ }
+
+ bitmap->item_index = rdpindex;
+ bitmap->id = rdpindex;
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_switch_os_surface(struct xrdp_mod* mod, int rdpindex)
+server_switch_os_surface(struct xrdp_mod *mod, int rdpindex)
{
- struct xrdp_wm* wm;
- struct xrdp_os_bitmap_item* bi;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_os_bitmap_item *bi;
+ struct xrdp_painter *p;
+
+ //g_writeln("server_switch_os_surface: id 0x%x", id);
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (rdpindex == -1)
+ {
+ //g_writeln("server_switch_os_surface: setting target_surface to screen");
+ wm->target_surface = wm->screen;
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p != 0)
+ {
+ //g_writeln("setting target");
+ wm_painter_set_target(p);
+ }
+
+ return 0;
+ }
- //g_writeln("server_switch_os_surface: id 0x%x", id);
- wm = (struct xrdp_wm*)(mod->wm);
- if (rdpindex == -1)
- {
- //g_writeln("server_switch_os_surface: setting target_surface to screen");
- wm->target_surface = wm->screen;
- p = (struct xrdp_painter*)(mod->painter);
- if (p != 0)
+ bi = xrdp_cache_get_os_bitmap(wm->cache, rdpindex);
+
+ if (bi != 0)
{
- //g_writeln("setting target");
- wm_painter_set_target(p);
+ //g_writeln("server_switch_os_surface: setting target_surface to rdpid %d", id);
+ wm->target_surface = bi->bitmap;
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p != 0)
+ {
+ //g_writeln("setting target");
+ wm_painter_set_target(p);
+ }
}
- return 0;
- }
- bi = xrdp_cache_get_os_bitmap(wm->cache, rdpindex);
- if (bi != 0)
- {
- //g_writeln("server_switch_os_surface: setting target_surface to rdpid %d", id);
- wm->target_surface = bi->bitmap;
- p = (struct xrdp_painter*)(mod->painter);
- if (p != 0)
+ else
{
- //g_writeln("setting target");
- wm_painter_set_target(p);
+ g_writeln("server_switch_os_surface: error finding id %d", rdpindex);
}
- }
- else
- {
- g_writeln("server_switch_os_surface: error finding id %d", rdpindex);
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_delete_os_surface(struct xrdp_mod* mod, int rdpindex)
+server_delete_os_surface(struct xrdp_mod *mod, int rdpindex)
{
- struct xrdp_wm* wm;
- struct xrdp_painter* p;
+ struct xrdp_wm *wm;
+ struct xrdp_painter *p;
- //g_writeln("server_delete_os_surface: id 0x%x", id);
- wm = (struct xrdp_wm*)(mod->wm);
- if (wm->target_surface->type == WND_TYPE_OFFSCREEN)
- {
- if (wm->target_surface->id == rdpindex)
+ //g_writeln("server_delete_os_surface: id 0x%x", id);
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (wm->target_surface->type == WND_TYPE_OFFSCREEN)
{
- g_writeln("server_delete_os_surface: setting target_surface to screen");
- wm->target_surface = wm->screen;
- p = (struct xrdp_painter*)(mod->painter);
- if (p != 0)
- {
- //g_writeln("setting target");
- wm_painter_set_target(p);
- }
+ if (wm->target_surface->id == rdpindex)
+ {
+ g_writeln("server_delete_os_surface: setting target_surface to screen");
+ wm->target_surface = wm->screen;
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p != 0)
+ {
+ //g_writeln("setting target");
+ wm_painter_set_target(p);
+ }
+ }
}
- }
- xrdp_cache_remove_os_bitmap(wm->cache, rdpindex);
- return 0;
+
+ xrdp_cache_remove_os_bitmap(wm->cache, rdpindex);
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_paint_rect_os(struct xrdp_mod* mod, int x, int y, int cx, int cy,
+server_paint_rect_os(struct xrdp_mod *mod, int x, int y, int cx, int cy,
int rdpindex, int srcx, int srcy)
{
- struct xrdp_wm* wm;
- struct xrdp_bitmap* b;
- struct xrdp_painter* p;
- struct xrdp_os_bitmap_item* bi;
+ struct xrdp_wm *wm;
+ struct xrdp_bitmap *b;
+ struct xrdp_painter *p;
+ struct xrdp_os_bitmap_item *bi;
+
+ p = (struct xrdp_painter *)(mod->painter);
+
+ if (p == 0)
+ {
+ return 0;
+ }
+
+ wm = (struct xrdp_wm *)(mod->wm);
+ bi = xrdp_cache_get_os_bitmap(wm->cache, rdpindex);
+
+ if (bi != 0)
+ {
+ b = bi->bitmap;
+ xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);
+ }
+ else
+ {
+ g_writeln("server_paint_rect_os: error finding id %d", rdpindex);
+ }
- p = (struct xrdp_painter*)(mod->painter);
- if (p == 0)
- {
return 0;
- }
- wm = (struct xrdp_wm*)(mod->wm);
- bi = xrdp_cache_get_os_bitmap(wm->cache, rdpindex);
- if (bi != 0)
- {
- b = bi->bitmap;
- xrdp_painter_copy(p, b, wm->target_surface, x, y, cx, cy, srcx, srcy);
- }
- else
- {
- g_writeln("server_paint_rect_os: error finding id %d", rdpindex);
- }
- return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_set_hints(struct xrdp_mod* mod, int hints, int mask)
+server_set_hints(struct xrdp_mod *mod, int hints, int mask)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- if (mask & 1)
- {
- if (hints & 1)
- {
- wm->hints |= 1;
- }
- else
+ wm = (struct xrdp_wm *)(mod->wm);
+
+ if (mask & 1)
{
- wm->hints &= ~1;
+ if (hints & 1)
+ {
+ wm->hints |= 1;
+ }
+ else
+ {
+ wm->hints &= ~1;
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
int DEFAULT_CC
-server_window_new_update(struct xrdp_mod* mod, int window_id,
- struct rail_window_state_order* window_state,
+server_window_new_update(struct xrdp_mod *mod, int window_id,
+ struct rail_window_state_order *window_state,
int flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_window_new_update(wm->session, window_id,
- window_state, flags);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_window_new_update(wm->session, window_id,
+ window_state, flags);
}
/*****************************************************************************/
int DEFAULT_CC
-server_window_delete(struct xrdp_mod* mod, int window_id)
+server_window_delete(struct xrdp_mod *mod, int window_id)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_window_delete(wm->session, window_id);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_window_delete(wm->session, window_id);
}
/*****************************************************************************/
int DEFAULT_CC
-server_window_icon(struct xrdp_mod* mod, int window_id, int cache_entry,
- int cache_id, struct rail_icon_info* icon_info,
+server_window_icon(struct xrdp_mod *mod, int window_id, int cache_entry,
+ int cache_id, struct rail_icon_info *icon_info,
int flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_window_icon(wm->session, window_id, cache_entry, cache_id,
- icon_info, flags);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_window_icon(wm->session, window_id, cache_entry, cache_id,
+ icon_info, flags);
}
/*****************************************************************************/
int DEFAULT_CC
-server_window_cached_icon(struct xrdp_mod* mod,
+server_window_cached_icon(struct xrdp_mod *mod,
int window_id, int cache_entry,
int cache_id, int flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_window_cached_icon(wm->session, window_id, cache_entry,
- cache_id, flags);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_window_cached_icon(wm->session, window_id, cache_entry,
+ cache_id, flags);
}
/*****************************************************************************/
int DEFAULT_CC
-server_notify_new_update(struct xrdp_mod* mod,
+server_notify_new_update(struct xrdp_mod *mod,
int window_id, int notify_id,
- struct rail_notify_state_order* notify_state,
+ struct rail_notify_state_order *notify_state,
int flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_notify_new_update(wm->session, window_id, notify_id,
- notify_state, flags);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_notify_new_update(wm->session, window_id, notify_id,
+ notify_state, flags);
}
/*****************************************************************************/
int DEFAULT_CC
-server_notify_delete(struct xrdp_mod* mod, int window_id,
+server_notify_delete(struct xrdp_mod *mod, int window_id,
int notify_id)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_notify_delete(wm->session, window_id, notify_id);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_notify_delete(wm->session, window_id, notify_id);
}
/*****************************************************************************/
int DEFAULT_CC
-server_monitored_desktop(struct xrdp_mod* mod,
- struct rail_monitored_desktop_order* mdo,
+server_monitored_desktop(struct xrdp_mod *mod,
+ struct rail_monitored_desktop_order *mdo,
int flags)
{
- struct xrdp_wm* wm;
+ struct xrdp_wm *wm;
- wm = (struct xrdp_wm*)(mod->wm);
- return libxrdp_monitored_desktop(wm->session, mdo, flags);
+ wm = (struct xrdp_wm *)(mod->wm);
+ return libxrdp_monitored_desktop(wm->session, mdo, flags);
}
diff --git a/xrdp/xrdp_painter.c b/xrdp/xrdp_painter.c
index b91be16d..0b867089 100644
--- a/xrdp/xrdp_painter.c
+++ b/xrdp/xrdp_painter.c
@@ -1,205 +1,218 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2012
-
- painter, gc
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * painter, gc
+ */
#include "xrdp.h"
/*****************************************************************************/
-struct xrdp_painter* APP_CC
-xrdp_painter_create(struct xrdp_wm* wm, struct xrdp_session* session)
+struct xrdp_painter *APP_CC
+xrdp_painter_create(struct xrdp_wm *wm, struct xrdp_session *session)
{
- struct xrdp_painter* self;
-
- self = (struct xrdp_painter*)g_malloc(sizeof(struct xrdp_painter), 1);
- self->wm = wm;
- self->session = session;
- self->rop = 0xcc; /* copy gota use 0xcc*/
- self->clip_children = 1;
- return self;
+ struct xrdp_painter *self;
+
+ self = (struct xrdp_painter *)g_malloc(sizeof(struct xrdp_painter), 1);
+ self->wm = wm;
+ self->session = session;
+ self->rop = 0xcc; /* copy gota use 0xcc*/
+ self->clip_children = 1;
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_painter_delete(struct xrdp_painter* self)
+xrdp_painter_delete(struct xrdp_painter *self)
{
- if (self == 0)
- {
- return;
- }
- g_free(self);
+ if (self == 0)
+ {
+ return;
+ }
+
+ g_free(self);
}
/*****************************************************************************/
int APP_CC
-wm_painter_set_target(struct xrdp_painter* self)
+wm_painter_set_target(struct xrdp_painter *self)
{
- int surface_index;
- int index;
- struct list* del_list;
-
- if (self->wm->target_surface->type == WND_TYPE_SCREEN)
- {
- if (self->wm->current_surface_index != 0xffff)
- {
- libxrdp_orders_send_switch_os_surface(self->session, 0xffff);
- self->wm->current_surface_index = 0xffff;
- }
- }
- else if (self->wm->target_surface->type == WND_TYPE_OFFSCREEN)
- {
- surface_index = self->wm->target_surface->item_index;
- if (surface_index != self->wm->current_surface_index)
- {
- if (self->wm->target_surface->tab_stop == 0) /* tab_stop is hack */
- {
- del_list = self->wm->cache->xrdp_os_del_list;
- index = list_index_of(del_list, surface_index);
- list_remove_item(del_list, index);
- libxrdp_orders_send_create_os_surface(self->session, surface_index,
- self->wm->target_surface->width,
- self->wm->target_surface->height,
- del_list);
- self->wm->target_surface->tab_stop = 1;
- list_clear(del_list);
- }
- libxrdp_orders_send_switch_os_surface(self->session, surface_index);
- self->wm->current_surface_index = surface_index;
- }
- }
- else
- {
- g_writeln("xrdp_painter_begin_update: bad target_surface");
- }
- return 0;
+ int surface_index;
+ int index;
+ struct list *del_list;
+
+ if (self->wm->target_surface->type == WND_TYPE_SCREEN)
+ {
+ if (self->wm->current_surface_index != 0xffff)
+ {
+ libxrdp_orders_send_switch_os_surface(self->session, 0xffff);
+ self->wm->current_surface_index = 0xffff;
+ }
+ }
+ else if (self->wm->target_surface->type == WND_TYPE_OFFSCREEN)
+ {
+ surface_index = self->wm->target_surface->item_index;
+
+ if (surface_index != self->wm->current_surface_index)
+ {
+ if (self->wm->target_surface->tab_stop == 0) /* tab_stop is hack */
+ {
+ del_list = self->wm->cache->xrdp_os_del_list;
+ index = list_index_of(del_list, surface_index);
+ list_remove_item(del_list, index);
+ libxrdp_orders_send_create_os_surface(self->session, surface_index,
+ self->wm->target_surface->width,
+ self->wm->target_surface->height,
+ del_list);
+ self->wm->target_surface->tab_stop = 1;
+ list_clear(del_list);
+ }
+
+ libxrdp_orders_send_switch_os_surface(self->session, surface_index);
+ self->wm->current_surface_index = surface_index;
+ }
+ }
+ else
+ {
+ g_writeln("xrdp_painter_begin_update: bad target_surface");
+ }
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_begin_update(struct xrdp_painter* self)
+xrdp_painter_begin_update(struct xrdp_painter *self)
{
- if (self == 0)
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ libxrdp_orders_init(self->session);
+ wm_painter_set_target(self);
return 0;
- }
- libxrdp_orders_init(self->session);
- wm_painter_set_target(self);
- return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_end_update(struct xrdp_painter* self)
+xrdp_painter_end_update(struct xrdp_painter *self)
{
- if (self == 0)
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ libxrdp_orders_send(self->session);
return 0;
- }
- libxrdp_orders_send(self->session);
- return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_font_needed(struct xrdp_painter* self)
+xrdp_painter_font_needed(struct xrdp_painter *self)
{
- if (self->font == 0)
- {
- self->font = self->wm->default_font;
- }
- return 0;
+ if (self->font == 0)
+ {
+ self->font = self->wm->default_font;
+ }
+
+ return 0;
}
#if 0
/*****************************************************************************/
/* returns boolean, true if there is something to draw */
static int APP_CC
-xrdp_painter_clip_adj(struct xrdp_painter* self, int* x, int* y,
- int* cx, int* cy)
+xrdp_painter_clip_adj(struct xrdp_painter *self, int *x, int *y,
+ int *cx, int *cy)
{
- int dx;
- int dy;
+ int dx;
+ int dy;
+
+ if (!self->use_clip)
+ {
+ return 1;
+ }
+
+ if (self->clip.left > *x)
+ {
+ dx = self->clip.left - *x;
+ }
+ else
+ {
+ dx = 0;
+ }
- if (!self->use_clip)
- {
+ if (self->clip.top > *y)
+ {
+ dy = self->clip.top - *y;
+ }
+ else
+ {
+ dy = 0;
+ }
+
+ if (*x + *cx > self->clip.right)
+ {
+ *cx = *cx - ((*x + *cx) - self->clip.right);
+ }
+
+ if (*y + *cy > self->clip.bottom)
+ {
+ *cy = *cy - ((*y + *cy) - self->clip.bottom);
+ }
+
+ *cx = *cx - dx;
+ *cy = *cy - dy;
+
+ if (*cx <= 0)
+ {
+ return 0;
+ }
+
+ if (*cy <= 0)
+ {
+ return 0;
+ }
+
+ *x = *x + dx;
+ *y = *y + dy;
return 1;
- }
- if (self->clip.left > *x)
- {
- dx = self->clip.left - *x;
- }
- else
- {
- dx = 0;
- }
- if (self->clip.top > *y)
- {
- dy = self->clip.top - *y;
- }
- else
- {
- dy = 0;
- }
- if (*x + *cx > self->clip.right)
- {
- *cx = *cx - ((*x + *cx) - self->clip.right);
- }
- if (*y + *cy > self->clip.bottom)
- {
- *cy = *cy - ((*y + *cy) - self->clip.bottom);
- }
- *cx = *cx - dx;
- *cy = *cy - dy;
- if (*cx <= 0)
- {
- return 0;
- }
- if (*cy <= 0)
- {
- return 0;
- }
- *x = *x + dx;
- *y = *y + dy;
- return 1;
}
#endif
/*****************************************************************************/
int APP_CC
-xrdp_painter_set_clip(struct xrdp_painter* self,
+xrdp_painter_set_clip(struct xrdp_painter *self,
int x, int y, int cx, int cy)
{
- self->use_clip = &self->clip;
- self->clip.left = x;
- self->clip.top = y;
- self->clip.right = x + cx;
- self->clip.bottom = y + cy;
- return 0;
+ self->use_clip = &self->clip;
+ self->clip.left = x;
+ self->clip.top = y;
+ self->clip.right = x + cx;
+ self->clip.bottom = y + cy;
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_clr_clip(struct xrdp_painter* self)
+xrdp_painter_clr_clip(struct xrdp_painter *self)
{
- self->use_clip = 0;
- return 0;
+ self->use_clip = 0;
+ return 0;
}
#if 0
@@ -207,631 +220,720 @@ xrdp_painter_clr_clip(struct xrdp_painter* self)
static int APP_CC
xrdp_painter_rop(int rop, int src, int dst)
{
- switch (rop & 0x0f)
- {
- case 0x0: return 0;
- case 0x1: return ~(src | dst);
- case 0x2: return (~src) & dst;
- case 0x3: return ~src;
- case 0x4: return src & (~dst);
- case 0x5: return ~(dst);
- case 0x6: return src ^ dst;
- case 0x7: return ~(src & dst);
- case 0x8: return src & dst;
- case 0x9: return ~(src) ^ dst;
- case 0xa: return dst;
- case 0xb: return (~src) | dst;
- case 0xc: return src;
- case 0xd: return src | (~dst);
- case 0xe: return src | dst;
- case 0xf: return ~0;
- }
- return dst;
+ switch (rop & 0x0f)
+ {
+ case 0x0:
+ return 0;
+ case 0x1:
+ return ~(src | dst);
+ case 0x2:
+ return (~src) & dst;
+ case 0x3:
+ return ~src;
+ case 0x4:
+ return src & (~dst);
+ case 0x5:
+ return ~(dst);
+ case 0x6:
+ return src ^ dst;
+ case 0x7:
+ return ~(src & dst);
+ case 0x8:
+ return src & dst;
+ case 0x9:
+ return ~(src) ^ dst;
+ case 0xa:
+ return dst;
+ case 0xb:
+ return (~src) | dst;
+ case 0xc:
+ return src;
+ case 0xd:
+ return src | (~dst);
+ case 0xe:
+ return src | dst;
+ case 0xf:
+ return ~0;
+ }
+
+ return dst;
}
#endif
/*****************************************************************************/
int APP_CC
-xrdp_painter_text_width(struct xrdp_painter* self, char* text)
+xrdp_painter_text_width(struct xrdp_painter *self, char *text)
{
- int index;
- int rv;
- int len;
- struct xrdp_font_char* font_item;
- twchar* wstr;
-
- xrdp_painter_font_needed(self);
- if (self->font == 0)
- {
- return 0;
- }
- if (text == 0)
- {
- return 0;
- }
- rv = 0;
- len = g_mbstowcs(0, text, 0);
- wstr = (twchar*)g_malloc((len + 2) * sizeof(twchar), 0);
- g_mbstowcs(wstr, text, len + 1);
- for (index = 0; index < len; index++)
- {
- font_item = self->font->font_items + wstr[index];
- rv = rv + font_item->incby;
- }
- g_free(wstr);
- return rv;
+ int index;
+ int rv;
+ int len;
+ struct xrdp_font_char *font_item;
+ twchar *wstr;
+
+ xrdp_painter_font_needed(self);
+
+ if (self->font == 0)
+ {
+ return 0;
+ }
+
+ if (text == 0)
+ {
+ return 0;
+ }
+
+ rv = 0;
+ len = g_mbstowcs(0, text, 0);
+ wstr = (twchar *)g_malloc((len + 2) * sizeof(twchar), 0);
+ g_mbstowcs(wstr, text, len + 1);
+
+ for (index = 0; index < len; index++)
+ {
+ font_item = self->font->font_items + wstr[index];
+ rv = rv + font_item->incby;
+ }
+
+ g_free(wstr);
+ return rv;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_text_height(struct xrdp_painter* self, char* text)
+xrdp_painter_text_height(struct xrdp_painter *self, char *text)
{
- int index;
- int rv;
- int len;
- struct xrdp_font_char* font_item;
- twchar* wstr;
-
- xrdp_painter_font_needed(self);
- if (self->font == 0)
- {
- return 0;
- }
- if (text == 0)
- {
- return 0;
- }
- rv = 0;
- len = g_mbstowcs(0, text, 0);
- wstr = (twchar*)g_malloc((len + 2) * sizeof(twchar), 0);
- g_mbstowcs(wstr, text, len + 1);
- for (index = 0; index < len; index++)
- {
- font_item = self->font->font_items + wstr[index];
- rv = MAX(rv, font_item->height);
- }
- g_free(wstr);
- return rv;
+ int index;
+ int rv;
+ int len;
+ struct xrdp_font_char *font_item;
+ twchar *wstr;
+
+ xrdp_painter_font_needed(self);
+
+ if (self->font == 0)
+ {
+ return 0;
+ }
+
+ if (text == 0)
+ {
+ return 0;
+ }
+
+ rv = 0;
+ len = g_mbstowcs(0, text, 0);
+ wstr = (twchar *)g_malloc((len + 2) * sizeof(twchar), 0);
+ g_mbstowcs(wstr, text, len + 1);
+
+ for (index = 0; index < len; index++)
+ {
+ font_item = self->font->font_items + wstr[index];
+ rv = MAX(rv, font_item->height);
+ }
+
+ g_free(wstr);
+ return rv;
}
/*****************************************************************************/
static int APP_CC
-xrdp_painter_setup_brush(struct xrdp_painter* self,
- struct xrdp_brush* out_brush,
- struct xrdp_brush* in_brush)
+xrdp_painter_setup_brush(struct xrdp_painter *self,
+ struct xrdp_brush *out_brush,
+ struct xrdp_brush *in_brush)
{
- int cache_id;
+ int cache_id;
+
+ g_memcpy(out_brush, in_brush, sizeof(struct xrdp_brush));
- g_memcpy(out_brush, in_brush, sizeof(struct xrdp_brush));
- if (in_brush->style == 3)
- {
- if (self->session->client_info->brush_cache_code == 1)
+ if (in_brush->style == 3)
{
- cache_id = xrdp_cache_add_brush(self->wm->cache, in_brush->pattern);
- g_memset(out_brush->pattern, 0, 8);
- out_brush->pattern[0] = cache_id;
- out_brush->style = 0x81;
+ if (self->session->client_info->brush_cache_code == 1)
+ {
+ cache_id = xrdp_cache_add_brush(self->wm->cache, in_brush->pattern);
+ g_memset(out_brush->pattern, 0, 8);
+ out_brush->pattern[0] = cache_id;
+ out_brush->style = 0x81;
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* fill in an area of the screen with one color */
int APP_CC
-xrdp_painter_fill_rect(struct xrdp_painter* self,
- struct xrdp_bitmap* dst,
+xrdp_painter_fill_rect(struct xrdp_painter *self,
+ struct xrdp_bitmap *dst,
int x, int y, int cx, int cy)
{
- struct xrdp_rect clip_rect;
- struct xrdp_rect draw_rect;
- struct xrdp_rect rect;
- struct xrdp_region* region;
- struct xrdp_brush brush;
- int k;
- int dx;
- int dy;
- int rop;
-
- if (self == 0)
- {
- return 0;
- }
+ struct xrdp_rect clip_rect;
+ struct xrdp_rect draw_rect;
+ struct xrdp_rect rect;
+ struct xrdp_region *region;
+ struct xrdp_brush brush;
+ int k;
+ int dx;
+ int dy;
+ int rop;
+
+ if (self == 0)
+ {
+ return 0;
+ }
- /* todo data */
+ /* todo data */
- if (dst->type == WND_TYPE_BITMAP) /* 0 */
- {
- return 0;
- }
- xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
- region = xrdp_region_create(self->wm);
- if (dst->type != WND_TYPE_OFFSCREEN)
- {
- xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy, region,
- self->clip_children);
- }
- else
- {
- xrdp_region_add_rect(region, &clip_rect);
- }
- x += dx;
- y += dy;
- if (self->mix_mode == 0 && self->rop == 0xcc)
- {
- k = 0;
- while (xrdp_region_get_rect(region, k, &rect) == 0)
+ if (dst->type == WND_TYPE_BITMAP) /* 0 */
+ {
+ return 0;
+ }
+
+ xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
+ region = xrdp_region_create(self->wm);
+
+ if (dst->type != WND_TYPE_OFFSCREEN)
+ {
+ xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy, region,
+ self->clip_children);
+ }
+ else
+ {
+ xrdp_region_add_rect(region, &clip_rect);
+ }
+
+ x += dx;
+ y += dy;
+
+ if (self->mix_mode == 0 && self->rop == 0xcc)
{
- if (rect_intersect(&rect, &clip_rect, &draw_rect))
- {
- libxrdp_orders_rect(self->session, x, y, cx, cy,
- self->fg_color, &draw_rect);
- }
- k++;
+ k = 0;
+
+ while (xrdp_region_get_rect(region, k, &rect) == 0)
+ {
+ if (rect_intersect(&rect, &clip_rect, &draw_rect))
+ {
+ libxrdp_orders_rect(self->session, x, y, cx, cy,
+ self->fg_color, &draw_rect);
+ }
+
+ k++;
+ }
}
- }
- else if (self->mix_mode == 0 &&
+ else if (self->mix_mode == 0 &&
((self->rop & 0xf) == 0x0 || /* black */
(self->rop & 0xf) == 0xf || /* white */
(self->rop & 0xf) == 0x5)) /* DSTINVERT */
- {
- k = 0;
- while (xrdp_region_get_rect(region, k, &rect) == 0)
{
- if (rect_intersect(&rect, &clip_rect, &draw_rect))
- {
- libxrdp_orders_dest_blt(self->session, x, y, cx, cy,
- self->rop, &draw_rect);
- }
- k++;
+ k = 0;
+
+ while (xrdp_region_get_rect(region, k, &rect) == 0)
+ {
+ if (rect_intersect(&rect, &clip_rect, &draw_rect))
+ {
+ libxrdp_orders_dest_blt(self->session, x, y, cx, cy,
+ self->rop, &draw_rect);
+ }
+
+ k++;
+ }
}
- }
- else
- {
- k = 0;
- rop = self->rop;
- /* if opcode is in the form 0x00, 0x11, 0x22, ... convert it */
- if (((rop & 0xf0) >> 4) == (rop & 0xf))
- {
- switch (rop)
- {
- case 0x66: /* xor */
- rop = 0x5a;
- break;
- case 0xaa: /* noop */
- rop = 0xfb;
- break;
- case 0xcc: /* copy */
- rop = 0xf0;
- break;
- case 0x88: /* and */
- rop = 0xc0;
- break;
- }
- }
- xrdp_painter_setup_brush(self, &brush, &self->brush);
- while (xrdp_region_get_rect(region, k, &rect) == 0)
+ else
{
- if (rect_intersect(&rect, &clip_rect, &draw_rect))
- {
- libxrdp_orders_pat_blt(self->session, x, y, cx, cy,
- rop, self->bg_color, self->fg_color,
- &brush, &draw_rect);
- }
- k++;
- }
- }
- xrdp_region_delete(region);
- return 0;
-}
+ k = 0;
+ rop = self->rop;
-/*****************************************************************************/
-int APP_CC
-xrdp_painter_draw_text(struct xrdp_painter* self,
- struct xrdp_bitmap* dst,
- int x, int y, const char* text)
-{
- int i;
- int f;
- int c;
- int k;
- int x1;
- int y1;
- int flags;
- int len;
- int index;
- int total_width;
- int total_height;
- int dx;
- int dy;
- char* data;
- struct xrdp_region* region;
- struct xrdp_rect rect;
- struct xrdp_rect clip_rect;
- struct xrdp_rect draw_rect;
- struct xrdp_font* font;
- struct xrdp_font_char* font_item;
- twchar* wstr;
-
- if (self == 0)
- {
- return 0;
- }
- len = g_mbstowcs(0, text, 0);
- if (len < 1)
- {
- return 0;
- }
+ /* if opcode is in the form 0x00, 0x11, 0x22, ... convert it */
+ if (((rop & 0xf0) >> 4) == (rop & 0xf))
+ {
+ switch (rop)
+ {
+ case 0x66: /* xor */
+ rop = 0x5a;
+ break;
+ case 0xaa: /* noop */
+ rop = 0xfb;
+ break;
+ case 0xcc: /* copy */
+ rop = 0xf0;
+ break;
+ case 0x88: /* and */
+ rop = 0xc0;
+ break;
+ }
+ }
- /* todo data */
+ xrdp_painter_setup_brush(self, &brush, &self->brush);
- if (dst->type == 0)
- {
- return 0;
- }
- xrdp_painter_font_needed(self);
- if (self->font == 0)
- {
+ while (xrdp_region_get_rect(region, k, &rect) == 0)
+ {
+ if (rect_intersect(&rect, &clip_rect, &draw_rect))
+ {
+ libxrdp_orders_pat_blt(self->session, x, y, cx, cy,
+ rop, self->bg_color, self->fg_color,
+ &brush, &draw_rect);
+ }
+
+ k++;
+ }
+ }
+
+ xrdp_region_delete(region);
return 0;
- }
- /* convert to wide char */
- wstr = (twchar*)g_malloc((len + 2) * sizeof(twchar), 0);
- g_mbstowcs(wstr, text, len + 1);
- font = self->font;
- f = 0;
- k = 0;
- total_width = 0;
- total_height = 0;
- data = (char*)g_malloc(len * 4, 1);
- for (index = 0; index < len; index++)
- {
- font_item = font->font_items + wstr[index];
- i = xrdp_cache_add_char(self->wm->cache, font_item);
- f = HIWORD(i);
- c = LOWORD(i);
- data[index * 2] = c;
- data[index * 2 + 1] = k;
- k = font_item->incby;
- total_width += k;
- total_height = MAX(total_height, font_item->height);
- }
- xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
- region = xrdp_region_create(self->wm);
- if (dst->type != WND_TYPE_OFFSCREEN)
- {
- xrdp_wm_get_vis_region(self->wm, dst, x, y, total_width, total_height,
- region, self->clip_children);
- }
- else
- {
- xrdp_region_add_rect(region, &clip_rect);
- }
- x += dx;
- y += dy;
- k = 0;
- while (xrdp_region_get_rect(region, k, &rect) == 0)
- {
- if (rect_intersect(&rect, &clip_rect, &draw_rect))
- {
- x1 = x;
- y1 = y + total_height;
- flags = 0x03; /* 0x03 0x73; TEXT2_IMPLICIT_X and something else */
- libxrdp_orders_text(self->session, f, flags, 0,
- self->fg_color, 0,
- x - 1, y - 1, x + total_width, y + total_height,
- 0, 0, 0, 0,
- x1, y1, data, len * 2, &draw_rect);
- }
- k++;
- }
- xrdp_region_delete(region);
- g_free(data);
- g_free(wstr);
- return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_draw_text2(struct xrdp_painter* self,
- struct xrdp_bitmap* dst,
- int font, int flags, int mixmode,
- int clip_left, int clip_top,
- int clip_right, int clip_bottom,
- int box_left, int box_top,
- int box_right, int box_bottom,
- int x, int y, char* data, int data_len)
+xrdp_painter_draw_text(struct xrdp_painter *self,
+ struct xrdp_bitmap *dst,
+ int x, int y, const char *text)
{
- struct xrdp_rect clip_rect;
- struct xrdp_rect draw_rect;
- struct xrdp_rect rect;
- struct xrdp_region* region;
- int k;
- int dx;
- int dy;
-
- if (self == 0)
- {
- return 0;
- }
+ int i;
+ int f;
+ int c;
+ int k;
+ int x1;
+ int y1;
+ int flags;
+ int len;
+ int index;
+ int total_width;
+ int total_height;
+ int dx;
+ int dy;
+ char *data;
+ struct xrdp_region *region;
+ struct xrdp_rect rect;
+ struct xrdp_rect clip_rect;
+ struct xrdp_rect draw_rect;
+ struct xrdp_font *font;
+ struct xrdp_font_char *font_item;
+ twchar *wstr;
+
+ if (self == 0)
+ {
+ return 0;
+ }
- /* todo data */
+ len = g_mbstowcs(0, text, 0);
- if (dst->type == WND_TYPE_BITMAP)
- {
- return 0;
- }
- xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
- region = xrdp_region_create(self->wm);
- if (dst->type != WND_TYPE_OFFSCREEN)
- {
- if (box_right - box_left > 1)
+ if (len < 1)
{
- xrdp_wm_get_vis_region(self->wm, dst, box_left, box_top,
- box_right - box_left, box_bottom - box_top,
- region, self->clip_children);
+ return 0;
}
- else
+
+ /* todo data */
+
+ if (dst->type == 0)
{
- xrdp_wm_get_vis_region(self->wm, dst, clip_left, clip_top,
- clip_right - clip_left, clip_bottom - clip_top,
- region, self->clip_children);
- }
- }
- else
- {
- xrdp_region_add_rect(region, &clip_rect);
- }
-
- clip_left += dx;
- clip_top += dy;
- clip_right += dx;
- clip_bottom += dy;
- box_left += dx;
- box_top += dy;
- box_right += dx;
- box_bottom += dy;
- x += dx;
- y += dy;
- k = 0;
- while (xrdp_region_get_rect(region, k, &rect) == 0)
- {
- if (rect_intersect(&rect, &clip_rect, &draw_rect))
- {
- libxrdp_orders_text(self->session, font, flags, mixmode,
- self->fg_color, self->bg_color,
- clip_left, clip_top, clip_right, clip_bottom,
- box_left, box_top, box_right, box_bottom,
- x, y, data, data_len, &draw_rect);
- }
- k++;
- }
- xrdp_region_delete(region);
- return 0;
-}
+ return 0;
+ }
-/*****************************************************************************/
-int APP_CC
-xrdp_painter_copy(struct xrdp_painter* self,
- struct xrdp_bitmap* src,
- struct xrdp_bitmap* dst,
- int x, int y, int cx, int cy,
- int srcx, int srcy)
-{
- struct xrdp_rect clip_rect;
- struct xrdp_rect draw_rect;
- struct xrdp_rect rect1;
- struct xrdp_rect rect2;
- struct xrdp_region* region;
- struct xrdp_bitmap* b;
- int i;
- int j;
- int k;
- int dx;
- int dy;
- int palette_id;
- int bitmap_id;
- int cache_id;
- int cache_idx;
- int dstx;
- int dsty;
- int w;
- int h;
-
- if (self == 0 || src == 0 || dst == 0)
- {
- return 0;
- }
+ xrdp_painter_font_needed(self);
- /* todo data */
+ if (self->font == 0)
+ {
+ return 0;
+ }
+
+ /* convert to wide char */
+ wstr = (twchar *)g_malloc((len + 2) * sizeof(twchar), 0);
+ g_mbstowcs(wstr, text, len + 1);
+ font = self->font;
+ f = 0;
+ k = 0;
+ total_width = 0;
+ total_height = 0;
+ data = (char *)g_malloc(len * 4, 1);
+
+ for (index = 0; index < len; index++)
+ {
+ font_item = font->font_items + wstr[index];
+ i = xrdp_cache_add_char(self->wm->cache, font_item);
+ f = HIWORD(i);
+ c = LOWORD(i);
+ data[index * 2] = c;
+ data[index * 2 + 1] = k;
+ k = font_item->incby;
+ total_width += k;
+ total_height = MAX(total_height, font_item->height);
+ }
- if (dst->type == WND_TYPE_BITMAP)
- {
- return 0;
- }
- if (src->type == WND_TYPE_SCREEN)
- {
xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
region = xrdp_region_create(self->wm);
+
if (dst->type != WND_TYPE_OFFSCREEN)
{
- xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,
- region, self->clip_children);
+ xrdp_wm_get_vis_region(self->wm, dst, x, y, total_width, total_height,
+ region, self->clip_children);
}
else
{
- xrdp_region_add_rect(region, &clip_rect);
+ xrdp_region_add_rect(region, &clip_rect);
}
+
x += dx;
y += dy;
- srcx += dx;
- srcy += dy;
k = 0;
- while (xrdp_region_get_rect(region, k, &rect1) == 0)
+
+ while (xrdp_region_get_rect(region, k, &rect) == 0)
{
- if (rect_intersect(&rect1, &clip_rect, &draw_rect))
- {
- libxrdp_orders_screen_blt(self->session, x, y, cx, cy,
- srcx, srcy, self->rop, &draw_rect);
- }
- k++;
+ if (rect_intersect(&rect, &clip_rect, &draw_rect))
+ {
+ x1 = x;
+ y1 = y + total_height;
+ flags = 0x03; /* 0x03 0x73; TEXT2_IMPLICIT_X and something else */
+ libxrdp_orders_text(self->session, f, flags, 0,
+ self->fg_color, 0,
+ x - 1, y - 1, x + total_width, y + total_height,
+ 0, 0, 0, 0,
+ x1, y1, data, len * 2, &draw_rect);
+ }
+
+ k++;
}
+
xrdp_region_delete(region);
- }
- else if (src->type == WND_TYPE_OFFSCREEN)
- {
- //g_writeln("xrdp_painter_copy: todo");
+ g_free(data);
+ g_free(wstr);
+ return 0;
+}
+
+/*****************************************************************************/
+int APP_CC
+xrdp_painter_draw_text2(struct xrdp_painter *self,
+ struct xrdp_bitmap *dst,
+ int font, int flags, int mixmode,
+ int clip_left, int clip_top,
+ int clip_right, int clip_bottom,
+ int box_left, int box_top,
+ int box_right, int box_bottom,
+ int x, int y, char *data, int data_len)
+{
+ struct xrdp_rect clip_rect;
+ struct xrdp_rect draw_rect;
+ struct xrdp_rect rect;
+ struct xrdp_region *region;
+ int k;
+ int dx;
+ int dy;
+
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ /* todo data */
+
+ if (dst->type == WND_TYPE_BITMAP)
+ {
+ return 0;
+ }
xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
region = xrdp_region_create(self->wm);
+
if (dst->type != WND_TYPE_OFFSCREEN)
{
- //g_writeln("off screen to screen");
- xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,
- region, self->clip_children);
+ if (box_right - box_left > 1)
+ {
+ xrdp_wm_get_vis_region(self->wm, dst, box_left, box_top,
+ box_right - box_left, box_bottom - box_top,
+ region, self->clip_children);
+ }
+ else
+ {
+ xrdp_wm_get_vis_region(self->wm, dst, clip_left, clip_top,
+ clip_right - clip_left, clip_bottom - clip_top,
+ region, self->clip_children);
+ }
}
else
{
- //g_writeln("off screen to off screen");
- xrdp_region_add_rect(region, &clip_rect);
+ xrdp_region_add_rect(region, &clip_rect);
}
+
+ clip_left += dx;
+ clip_top += dy;
+ clip_right += dx;
+ clip_bottom += dy;
+ box_left += dx;
+ box_top += dy;
+ box_right += dx;
+ box_bottom += dy;
x += dx;
y += dy;
-
- palette_id = 0;
- cache_id = 255; // todo
- cache_idx = src->item_index; // todo
-
k = 0;
- while (xrdp_region_get_rect(region, k, &rect1) == 0)
+
+ while (xrdp_region_get_rect(region, k, &rect) == 0)
{
- if (rect_intersect(&rect1, &clip_rect, &rect2))
- {
- MAKERECT(rect1, x, y, cx, cy);
- if (rect_intersect(&rect2, &rect1, &draw_rect))
+ if (rect_intersect(&rect, &clip_rect, &draw_rect))
{
- libxrdp_orders_mem_blt(self->session, cache_id, palette_id,
- x, y, cx, cy, self->rop, srcx, srcy,
- cache_idx, &draw_rect);
+ libxrdp_orders_text(self->session, font, flags, mixmode,
+ self->fg_color, self->bg_color,
+ clip_left, clip_top, clip_right, clip_bottom,
+ box_left, box_top, box_right, box_bottom,
+ x, y, data, data_len, &draw_rect);
}
- }
- k++;
+
+ k++;
}
+
xrdp_region_delete(region);
- }
- else if (src->data != 0)
- /* todo, the non bitmap cache part is gone, it should be put back */
- {
- xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
- region = xrdp_region_create(self->wm);
- if (dst->type != WND_TYPE_OFFSCREEN)
+ return 0;
+}
+
+/*****************************************************************************/
+int APP_CC
+xrdp_painter_copy(struct xrdp_painter *self,
+ struct xrdp_bitmap *src,
+ struct xrdp_bitmap *dst,
+ int x, int y, int cx, int cy,
+ int srcx, int srcy)
+{
+ struct xrdp_rect clip_rect;
+ struct xrdp_rect draw_rect;
+ struct xrdp_rect rect1;
+ struct xrdp_rect rect2;
+ struct xrdp_region *region;
+ struct xrdp_bitmap *b;
+ int i;
+ int j;
+ int k;
+ int dx;
+ int dy;
+ int palette_id;
+ int bitmap_id;
+ int cache_id;
+ int cache_idx;
+ int dstx;
+ int dsty;
+ int w;
+ int h;
+
+ if (self == 0 || src == 0 || dst == 0)
{
- xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,
- region, self->clip_children);
+ return 0;
}
- else
+
+ /* todo data */
+
+ if (dst->type == WND_TYPE_BITMAP)
{
- xrdp_region_add_rect(region, &clip_rect);
+ return 0;
}
- x += dx;
- y += dy;
- palette_id = 0;
- j = srcy;
- while (j < (srcy + cy))
- {
- i = srcx;
- while (i < (srcx + cx))
- {
- w = MIN(64, ((srcx + cx) - i));
- h = MIN(64, ((srcy + cy) - j));
- b = xrdp_bitmap_create(w, h, self->wm->screen->bpp, 0, self->wm);
- xrdp_bitmap_copy_box_with_crc(src, b, i, j, w, h);
- bitmap_id = xrdp_cache_add_bitmap(self->wm->cache, b, self->wm->hints);
- cache_id = HIWORD(bitmap_id);
- cache_idx = LOWORD(bitmap_id);
- dstx = (x + i) - srcx;
- dsty = (y + j) - srcy;
+
+ if (src->type == WND_TYPE_SCREEN)
+ {
+ xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
+ region = xrdp_region_create(self->wm);
+
+ if (dst->type != WND_TYPE_OFFSCREEN)
+ {
+ xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,
+ region, self->clip_children);
+ }
+ else
+ {
+ xrdp_region_add_rect(region, &clip_rect);
+ }
+
+ x += dx;
+ y += dy;
+ srcx += dx;
+ srcy += dy;
k = 0;
+
while (xrdp_region_get_rect(region, k, &rect1) == 0)
{
- if (rect_intersect(&rect1, &clip_rect, &rect2))
- {
- MAKERECT(rect1, dstx, dsty, w, h);
- if (rect_intersect(&rect2, &rect1, &draw_rect))
+ if (rect_intersect(&rect1, &clip_rect, &draw_rect))
{
- libxrdp_orders_mem_blt(self->session, cache_id, palette_id,
- dstx, dsty, w, h, self->rop, 0, 0,
- cache_idx, &draw_rect);
+ libxrdp_orders_screen_blt(self->session, x, y, cx, cy,
+ srcx, srcy, self->rop, &draw_rect);
}
- }
- k++;
+
+ k++;
}
- i += 64;
- }
- j += 64;
+
+ xrdp_region_delete(region);
}
- xrdp_region_delete(region);
- }
- return 0;
+ else if (src->type == WND_TYPE_OFFSCREEN)
+ {
+ //g_writeln("xrdp_painter_copy: todo");
+
+ xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
+ region = xrdp_region_create(self->wm);
+
+ if (dst->type != WND_TYPE_OFFSCREEN)
+ {
+ //g_writeln("off screen to screen");
+ xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,
+ region, self->clip_children);
+ }
+ else
+ {
+ //g_writeln("off screen to off screen");
+ xrdp_region_add_rect(region, &clip_rect);
+ }
+
+ x += dx;
+ y += dy;
+
+ palette_id = 0;
+ cache_id = 255; // todo
+ cache_idx = src->item_index; // todo
+
+ k = 0;
+
+ while (xrdp_region_get_rect(region, k, &rect1) == 0)
+ {
+ if (rect_intersect(&rect1, &clip_rect, &rect2))
+ {
+ MAKERECT(rect1, x, y, cx, cy);
+
+ if (rect_intersect(&rect2, &rect1, &draw_rect))
+ {
+ libxrdp_orders_mem_blt(self->session, cache_id, palette_id,
+ x, y, cx, cy, self->rop, srcx, srcy,
+ cache_idx, &draw_rect);
+ }
+ }
+
+ k++;
+ }
+
+ xrdp_region_delete(region);
+ }
+ else if (src->data != 0)
+ /* todo, the non bitmap cache part is gone, it should be put back */
+ {
+ xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
+ region = xrdp_region_create(self->wm);
+
+ if (dst->type != WND_TYPE_OFFSCREEN)
+ {
+ xrdp_wm_get_vis_region(self->wm, dst, x, y, cx, cy,
+ region, self->clip_children);
+ }
+ else
+ {
+ xrdp_region_add_rect(region, &clip_rect);
+ }
+
+ x += dx;
+ y += dy;
+ palette_id = 0;
+ j = srcy;
+
+ while (j < (srcy + cy))
+ {
+ i = srcx;
+
+ while (i < (srcx + cx))
+ {
+ w = MIN(64, ((srcx + cx) - i));
+ h = MIN(64, ((srcy + cy) - j));
+ b = xrdp_bitmap_create(w, h, self->wm->screen->bpp, 0, self->wm);
+ xrdp_bitmap_copy_box_with_crc(src, b, i, j, w, h);
+ bitmap_id = xrdp_cache_add_bitmap(self->wm->cache, b, self->wm->hints);
+ cache_id = HIWORD(bitmap_id);
+ cache_idx = LOWORD(bitmap_id);
+ dstx = (x + i) - srcx;
+ dsty = (y + j) - srcy;
+ k = 0;
+
+ while (xrdp_region_get_rect(region, k, &rect1) == 0)
+ {
+ if (rect_intersect(&rect1, &clip_rect, &rect2))
+ {
+ MAKERECT(rect1, dstx, dsty, w, h);
+
+ if (rect_intersect(&rect2, &rect1, &draw_rect))
+ {
+ libxrdp_orders_mem_blt(self->session, cache_id, palette_id,
+ dstx, dsty, w, h, self->rop, 0, 0,
+ cache_idx, &draw_rect);
+ }
+ }
+
+ k++;
+ }
+
+ i += 64;
+ }
+
+ j += 64;
+ }
+
+ xrdp_region_delete(region);
+ }
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_painter_line(struct xrdp_painter* self,
- struct xrdp_bitmap* dst,
+xrdp_painter_line(struct xrdp_painter *self,
+ struct xrdp_bitmap *dst,
int x1, int y1, int x2, int y2)
{
- struct xrdp_rect clip_rect;
- struct xrdp_rect draw_rect;
- struct xrdp_rect rect;
- struct xrdp_region* region;
- int k;
- int dx;
- int dy;
- int rop;
-
- if (self == 0)
- {
- return 0;
- }
+ struct xrdp_rect clip_rect;
+ struct xrdp_rect draw_rect;
+ struct xrdp_rect rect;
+ struct xrdp_region *region;
+ int k;
+ int dx;
+ int dy;
+ int rop;
+
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ /* todo data */
+
+ if (dst->type == WND_TYPE_BITMAP)
+ {
+ return 0;
+ }
+
+ xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
+ region = xrdp_region_create(self->wm);
- /* todo data */
+ if (dst->type != WND_TYPE_OFFSCREEN)
+ {
+ xrdp_wm_get_vis_region(self->wm, dst, MIN(x1, x2), MIN(y1, y2),
+ g_abs(x1 - x2) + 1, g_abs(y1 - y2) + 1,
+ region, self->clip_children);
+ }
+ else
+ {
+ xrdp_region_add_rect(region, &clip_rect);
+ }
+
+ x1 += dx;
+ y1 += dy;
+ x2 += dx;
+ y2 += dy;
+ k = 0;
+ rop = self->rop;
+
+ if (rop < 0x01 || rop > 0x10)
+ {
+ rop = (rop & 0xf) + 1;
+ }
+
+ while (xrdp_region_get_rect(region, k, &rect) == 0)
+ {
+ if (rect_intersect(&rect, &clip_rect, &draw_rect))
+ {
+ libxrdp_orders_line(self->session, 1, x1, y1, x2, y2,
+ rop, self->bg_color,
+ &self->pen, &draw_rect);
+ }
- if (dst->type == WND_TYPE_BITMAP)
- {
+ k++;
+ }
+
+ xrdp_region_delete(region);
return 0;
- }
- xrdp_bitmap_get_screen_clip(dst, self, &clip_rect, &dx, &dy);
- region = xrdp_region_create(self->wm);
- if (dst->type != WND_TYPE_OFFSCREEN)
- {
- xrdp_wm_get_vis_region(self->wm, dst, MIN(x1, x2), MIN(y1, y2),
- g_abs(x1 - x2) + 1, g_abs(y1 - y2) + 1,
- region, self->clip_children);
- }
- else
- {
- xrdp_region_add_rect(region, &clip_rect);
- }
- x1 += dx;
- y1 += dy;
- x2 += dx;
- y2 += dy;
- k = 0;
- rop = self->rop;
- if (rop < 0x01 || rop > 0x10)
- {
- rop = (rop & 0xf) + 1;
- }
- while (xrdp_region_get_rect(region, k, &rect) == 0)
- {
- if (rect_intersect(&rect, &clip_rect, &draw_rect))
- {
- libxrdp_orders_line(self->session, 1, x1, y1, x2, y2,
- rop, self->bg_color,
- &self->pen, &draw_rect);
- }
- k++;
- }
- xrdp_region_delete(region);
- return 0;
}
diff --git a/xrdp/xrdp_process.c b/xrdp/xrdp_process.c
index 7a88d524..e3b846ea 100644
--- a/xrdp/xrdp_process.c
+++ b/xrdp/xrdp_process.c
@@ -1,24 +1,22 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- main rdp process
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * main rdp process
+ */
#include "xrdp.h"
@@ -26,60 +24,64 @@ static int g_session_id = 0;
/*****************************************************************************/
/* always called from xrdp_listen thread */
-struct xrdp_process* APP_CC
-xrdp_process_create(struct xrdp_listen* owner, tbus done_event)
+struct xrdp_process *APP_CC
+xrdp_process_create(struct xrdp_listen *owner, tbus done_event)
{
- struct xrdp_process* self;
- char event_name[256];
- int pid;
-
- self = (struct xrdp_process*)g_malloc(sizeof(struct xrdp_process), 1);
- self->lis_layer = owner;
- self->done_event = done_event;
- g_session_id++;
- self->session_id = g_session_id;
- pid = g_getpid();
- g_snprintf(event_name, 255, "xrdp_%8.8x_process_self_term_event_%8.8x",
- pid, self->session_id);
- self->self_term_event = g_create_wait_obj(event_name);
- return self;
+ struct xrdp_process *self;
+ char event_name[256];
+ int pid;
+
+ self = (struct xrdp_process *)g_malloc(sizeof(struct xrdp_process), 1);
+ self->lis_layer = owner;
+ self->done_event = done_event;
+ g_session_id++;
+ self->session_id = g_session_id;
+ pid = g_getpid();
+ g_snprintf(event_name, 255, "xrdp_%8.8x_process_self_term_event_%8.8x",
+ pid, self->session_id);
+ self->self_term_event = g_create_wait_obj(event_name);
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_process_delete(struct xrdp_process* self)
+xrdp_process_delete(struct xrdp_process *self)
{
- if (self == 0)
- {
- return;
- }
- g_delete_wait_obj(self->self_term_event);
- libxrdp_exit(self->session);
- xrdp_wm_delete(self->wm);
- trans_delete(self->server_trans);
- g_free(self);
+ if (self == 0)
+ {
+ return;
+ }
+
+ g_delete_wait_obj(self->self_term_event);
+ libxrdp_exit(self->session);
+ xrdp_wm_delete(self->wm);
+ trans_delete(self->server_trans);
+ g_free(self);
}
/*****************************************************************************/
static int APP_CC
-xrdp_process_loop(struct xrdp_process* self)
+xrdp_process_loop(struct xrdp_process *self)
{
- int rv;
-
- rv = 0;
- if (self->session != 0)
- {
- rv = libxrdp_process_data(self->session);
- }
- if ((self->wm == 0) && (self->session->up_and_running) && (rv == 0))
- {
- DEBUG(("calling xrdp_wm_init and creating wm"));
- self->wm = xrdp_wm_create(self, self->session->client_info);
- /* at this point the wm(window manager) is create and wm::login_mode is
- zero and login_mode_event is set so xrdp_wm_init should be called by
- xrdp_wm_check_wait_objs */
- }
- return rv;
+ int rv;
+
+ rv = 0;
+
+ if (self->session != 0)
+ {
+ rv = libxrdp_process_data(self->session);
+ }
+
+ if ((self->wm == 0) && (self->session->up_and_running) && (rv == 0))
+ {
+ DEBUG(("calling xrdp_wm_init and creating wm"));
+ self->wm = xrdp_wm_create(self, self->session->client_info);
+ /* at this point the wm(window manager) is create and wm::login_mode is
+ zero and login_mode_event is set so xrdp_wm_init should be called by
+ xrdp_wm_check_wait_objs */
+ }
+
+ return rv;
}
/*****************************************************************************/
@@ -88,113 +90,125 @@ xrdp_process_loop(struct xrdp_process* self)
static int DEFAULT_CC
xrdp_is_term(void)
{
- return g_is_term();
+ return g_is_term();
}
/*****************************************************************************/
static int APP_CC
-xrdp_process_mod_end(struct xrdp_process* self)
+xrdp_process_mod_end(struct xrdp_process *self)
{
- if (self->wm != 0)
- {
- if (self->wm->mm != 0)
+ if (self->wm != 0)
{
- if (self->wm->mm->mod != 0)
- {
- if (self->wm->mm->mod->mod_end != 0)
+ if (self->wm->mm != 0)
{
- return self->wm->mm->mod->mod_end(self->wm->mm->mod);
+ if (self->wm->mm->mod != 0)
+ {
+ if (self->wm->mm->mod->mod_end != 0)
+ {
+ return self->wm->mm->mod->mod_end(self->wm->mm->mod);
+ }
+ }
}
- }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
static int DEFAULT_CC
-xrdp_process_data_in(struct trans* self)
+xrdp_process_data_in(struct trans *self)
{
- struct xrdp_process* pro;
-
- DEBUG(("xrdp_process_data_in"));
- pro = (struct xrdp_process*)(self->callback_data);
- if (xrdp_process_loop(pro) != 0)
- {
- return 1;
- }
- return 0;
+ struct xrdp_process *pro;
+
+ DEBUG(("xrdp_process_data_in"));
+ pro = (struct xrdp_process *)(self->callback_data);
+
+ if (xrdp_process_loop(pro) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_process_main_loop(struct xrdp_process* self)
+xrdp_process_main_loop(struct xrdp_process *self)
{
- int robjs_count;
- int wobjs_count;
- int cont;
- int timeout = 0;
- tbus robjs[32];
- tbus wobjs[32];
- tbus term_obj;
-
- DEBUG(("xrdp_process_main_loop"));
- self->status = 1;
- self->server_trans->trans_data_in = xrdp_process_data_in;
- self->server_trans->callback_data = self;
- self->session = libxrdp_init((tbus)self, self->server_trans);
- /* this callback function is in xrdp_wm.c */
- self->session->callback = callback;
- /* this function is just above */
- self->session->is_term = xrdp_is_term;
- if (libxrdp_process_incomming(self->session) == 0)
- {
- term_obj = g_get_term_event();
- cont = 1;
- while (cont)
+ int robjs_count;
+ int wobjs_count;
+ int cont;
+ int timeout = 0;
+ tbus robjs[32];
+ tbus wobjs[32];
+ tbus term_obj;
+
+ DEBUG(("xrdp_process_main_loop"));
+ self->status = 1;
+ self->server_trans->trans_data_in = xrdp_process_data_in;
+ self->server_trans->callback_data = self;
+ self->session = libxrdp_init((tbus)self, self->server_trans);
+ /* this callback function is in xrdp_wm.c */
+ self->session->callback = callback;
+ /* this function is just above */
+ self->session->is_term = xrdp_is_term;
+
+ if (libxrdp_process_incomming(self->session) == 0)
{
- /* build the wait obj list */
- timeout = -1;
- robjs_count = 0;
- wobjs_count = 0;
- robjs[robjs_count++] = term_obj;
- robjs[robjs_count++] = self->self_term_event;
- xrdp_wm_get_wait_objs(self->wm, robjs, &robjs_count,
- wobjs, &wobjs_count, &timeout);
- trans_get_wait_objs(self->server_trans, robjs, &robjs_count);
- /* wait */
- if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0)
- {
- /* error, should not get here */
- g_sleep(100);
- }
- if (g_is_wait_obj_set(term_obj)) /* term */
- {
- break;
- }
- if (g_is_wait_obj_set(self->self_term_event))
- {
- break;
- }
- if (xrdp_wm_check_wait_objs(self->wm) != 0)
- {
- break;
- }
- if (trans_check_wait_objs(self->server_trans) != 0)
- {
- break;
- }
+ term_obj = g_get_term_event();
+ cont = 1;
+
+ while (cont)
+ {
+ /* build the wait obj list */
+ timeout = -1;
+ robjs_count = 0;
+ wobjs_count = 0;
+ robjs[robjs_count++] = term_obj;
+ robjs[robjs_count++] = self->self_term_event;
+ xrdp_wm_get_wait_objs(self->wm, robjs, &robjs_count,
+ wobjs, &wobjs_count, &timeout);
+ trans_get_wait_objs(self->server_trans, robjs, &robjs_count);
+
+ /* wait */
+ if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0)
+ {
+ /* error, should not get here */
+ g_sleep(100);
+ }
+
+ if (g_is_wait_obj_set(term_obj)) /* term */
+ {
+ break;
+ }
+
+ if (g_is_wait_obj_set(self->self_term_event))
+ {
+ break;
+ }
+
+ if (xrdp_wm_check_wait_objs(self->wm) != 0)
+ {
+ break;
+ }
+
+ if (trans_check_wait_objs(self->server_trans) != 0)
+ {
+ break;
+ }
+ }
+
+ libxrdp_disconnect(self->session);
}
- libxrdp_disconnect(self->session);
- }
- else
- {
- g_writeln("xrdp_process_main_loop: libxrdp_process_incomming failed");
- }
- xrdp_process_mod_end(self);
- libxrdp_exit(self->session);
- self->session = 0;
- self->status = -1;
- g_set_wait_obj(self->done_event);
- return 0;
+ else
+ {
+ g_writeln("xrdp_process_main_loop: libxrdp_process_incomming failed");
+ }
+
+ xrdp_process_mod_end(self);
+ libxrdp_exit(self->session);
+ self->session = 0;
+ self->status = -1;
+ g_set_wait_obj(self->done_event);
+ return 0;
}
diff --git a/xrdp/xrdp_region.c b/xrdp/xrdp_region.c
index db046a30..8dc6854b 100644
--- a/xrdp/xrdp_region.c
+++ b/xrdp/xrdp_region.c
@@ -1,297 +1,316 @@
-
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- region
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * region
+ */
#include "xrdp.h"
/*****************************************************************************/
-struct xrdp_region* APP_CC
-xrdp_region_create(struct xrdp_wm* wm)
+struct xrdp_region *APP_CC
+xrdp_region_create(struct xrdp_wm *wm)
{
- struct xrdp_region* self;
+ struct xrdp_region *self;
- self = (struct xrdp_region*)g_malloc(sizeof(struct xrdp_region), 1);
- self->wm = wm;
- self->rects = list_create();
- self->rects->auto_free = 1;
- return self;
+ self = (struct xrdp_region *)g_malloc(sizeof(struct xrdp_region), 1);
+ self->wm = wm;
+ self->rects = list_create();
+ self->rects->auto_free = 1;
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_region_delete(struct xrdp_region* self)
+xrdp_region_delete(struct xrdp_region *self)
{
- if (self == 0)
- {
- return;
- }
- list_delete(self->rects);
- g_free(self);
+ if (self == 0)
+ {
+ return;
+ }
+
+ list_delete(self->rects);
+ g_free(self);
}
/*****************************************************************************/
int APP_CC
-xrdp_region_add_rect(struct xrdp_region* self, struct xrdp_rect* rect)
+xrdp_region_add_rect(struct xrdp_region *self, struct xrdp_rect *rect)
{
- struct xrdp_rect* r;
+ struct xrdp_rect *r;
- r = (struct xrdp_rect*)g_malloc(sizeof(struct xrdp_rect), 1);
- *r = *rect;
- list_add_item(self->rects, (long)r);
- return 0;
+ r = (struct xrdp_rect *)g_malloc(sizeof(struct xrdp_rect), 1);
+ *r = *rect;
+ list_add_item(self->rects, (long)r);
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_region_insert_rect(struct xrdp_region* self, int i, int left,
+xrdp_region_insert_rect(struct xrdp_region *self, int i, int left,
int top, int right, int bottom)
{
- struct xrdp_rect* r;
+ struct xrdp_rect *r;
- r = (struct xrdp_rect*)g_malloc(sizeof(struct xrdp_rect), 1);
- r->left = left;
- r->top = top;
- r->right = right;
- r->bottom = bottom;
- list_insert_item(self->rects, i, (long)r);
- return 0;
+ r = (struct xrdp_rect *)g_malloc(sizeof(struct xrdp_rect), 1);
+ r->left = left;
+ r->top = top;
+ r->right = right;
+ r->bottom = bottom;
+ list_insert_item(self->rects, i, (long)r);
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_region_subtract_rect(struct xrdp_region* self,
- struct xrdp_rect* rect)
+xrdp_region_subtract_rect(struct xrdp_region *self,
+ struct xrdp_rect *rect)
{
- struct xrdp_rect* r;
- struct xrdp_rect rect1;
- int i;
+ struct xrdp_rect *r;
+ struct xrdp_rect rect1;
+ int i;
- for (i = self->rects->count - 1; i >= 0; i--)
- {
- r = (struct xrdp_rect*)list_get_item(self->rects, i);
- rect1 = *r;
- r = &rect1;
- if (rect->left <= r->left &&
- rect->top <= r->top &&
- rect->right >= r->right &&
- rect->bottom >= r->bottom)
- { /* rect is not visible */
- list_remove_item(self->rects, i);
- }
- else if (rect->right < r->left ||
- rect->bottom < r->top ||
- rect->top > r->bottom ||
- rect->left > r->right)
- { /* rect are not related */
- }
- else if (rect->left <= r->left &&
- rect->right >= r->right &&
- rect->bottom < r->bottom &&
- rect->top <= r->top)
- { /* partially covered(whole top) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, rect->bottom,
- r->right, r->bottom);
- }
- else if (rect->top <= r->top &&
- rect->bottom >= r->bottom &&
- rect->right < r->right &&
- rect->left <= r->left)
- { /* partially covered(left) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, rect->right, r->top,
- r->right, r->bottom);
- }
- else if (rect->left <= r->left &&
- rect->right >= r->right &&
- rect->top > r->top &&
- rect->bottom >= r->bottom)
- { /* partially covered(bottom) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- }
- else if (rect->top <= r->top &&
- rect->bottom >= r->bottom &&
- rect->left > r->left &&
- rect->right >= r->right)
- { /* partially covered(right) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- rect->left, r->bottom);
- }
- else if (rect->left <= r->left &&
- rect->top <= r->top &&
- rect->right < r->right &&
- rect->bottom < r->bottom)
- { /* partially covered(top left) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, rect->right, r->top,
- r->right, rect->bottom);
- xrdp_region_insert_rect(self, i, r->left, rect->bottom,
- r->right, r->bottom);
- }
- else if (rect->left <= r->left &&
- rect->bottom >= r->bottom &&
- rect->right < r->right &&
- rect->top > r->top)
- { /* partially covered(bottom left) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- xrdp_region_insert_rect(self, i, rect->right, rect->top,
- r->right, r->bottom);
- }
- else if (rect->left > r->left &&
- rect->right >= r->right &&
- rect->top <= r->top &&
- rect->bottom < r->bottom)
- { /* partially covered(top right) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- rect->left, r->bottom);
- xrdp_region_insert_rect(self, i, rect->left, rect->bottom,
- r->right, r->bottom);
- }
- else if (rect->left > r->left &&
- rect->right >= r->right &&
- rect->top > r->top &&
- rect->bottom >= r->bottom)
- { /* partially covered(bottom right) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- xrdp_region_insert_rect(self, i, r->left, rect->top,
- rect->left, r->bottom);
- }
- else if (rect->left > r->left &&
- rect->top <= r->top &&
- rect->right < r->right &&
- rect->bottom >= r->bottom)
- { /* 2 rects, one on each end */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- rect->left, r->bottom);
- xrdp_region_insert_rect(self, i, rect->right, r->top,
- r->right, r->bottom);
- }
- else if (rect->left <= r->left &&
- rect->top > r->top &&
- rect->right >= r->right &&
- rect->bottom < r->bottom)
- { /* 2 rects, one on each end */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- xrdp_region_insert_rect(self, i, r->left, rect->bottom,
- r->right, r->bottom);
- }
- else if (rect->left > r->left &&
- rect->right < r->right &&
- rect->top <= r->top &&
- rect->bottom < r->bottom)
- { /* partially covered(top) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- rect->left, r->bottom);
- xrdp_region_insert_rect(self, i, rect->left, rect->bottom,
- rect->right, r->bottom);
- xrdp_region_insert_rect(self, i, rect->right, r->top,
- r->right, r->bottom);
- }
- else if (rect->top > r->top &&
- rect->bottom < r->bottom &&
- rect->left <= r->left &&
- rect->right < r->right)
- { /* partially covered(left) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- xrdp_region_insert_rect(self, i, rect->right, rect->top,
- r->right, rect->bottom);
- xrdp_region_insert_rect(self, i, r->left, rect->bottom,
- r->right, r->bottom);
- }
- else if (rect->left > r->left &&
- rect->right < r->right &&
- rect->bottom >= r->bottom &&
- rect->top > r->top)
- { /* partially covered(bottom) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- rect->left, r->bottom);
- xrdp_region_insert_rect(self, i, rect->left, r->top,
- rect->right, rect->top);
- xrdp_region_insert_rect(self, i, rect->right, r->top,
- r->right, r->bottom);
- }
- else if (rect->top > r->top &&
- rect->bottom < r->bottom &&
- rect->right >= r->right &&
- rect->left > r->left)
- { /* partially covered(right) */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- xrdp_region_insert_rect(self, i, r->left, rect->top,
- rect->left, rect->bottom);
- xrdp_region_insert_rect(self, i, r->left, rect->bottom,
- r->right, r->bottom);
- }
- else if (rect->left > r->left &&
- rect->top > r->top &&
- rect->right < r->right &&
- rect->bottom < r->bottom)
- { /* totally contained, 4 rects */
- list_remove_item(self->rects, i);
- xrdp_region_insert_rect(self, i, r->left, r->top,
- r->right, rect->top);
- xrdp_region_insert_rect(self, i, r->left, rect->top,
- rect->left, rect->bottom);
- xrdp_region_insert_rect(self, i, r->left, rect->bottom,
- r->right, r->bottom);
- xrdp_region_insert_rect(self, i, rect->right, rect->top,
- r->right, rect->bottom);
- }
- else
+ for (i = self->rects->count - 1; i >= 0; i--)
{
- g_writeln("error in xrdp_region_subtract_rect");
+ r = (struct xrdp_rect *)list_get_item(self->rects, i);
+ rect1 = *r;
+ r = &rect1;
+
+ if (rect->left <= r->left &&
+ rect->top <= r->top &&
+ rect->right >= r->right &&
+ rect->bottom >= r->bottom)
+ {
+ /* rect is not visible */
+ list_remove_item(self->rects, i);
+ }
+ else if (rect->right < r->left ||
+ rect->bottom < r->top ||
+ rect->top > r->bottom ||
+ rect->left > r->right)
+ {
+ /* rect are not related */
+ }
+ else if (rect->left <= r->left &&
+ rect->right >= r->right &&
+ rect->bottom < r->bottom &&
+ rect->top <= r->top)
+ {
+ /* partially covered(whole top) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, rect->bottom,
+ r->right, r->bottom);
+ }
+ else if (rect->top <= r->top &&
+ rect->bottom >= r->bottom &&
+ rect->right < r->right &&
+ rect->left <= r->left)
+ {
+ /* partially covered(left) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, rect->right, r->top,
+ r->right, r->bottom);
+ }
+ else if (rect->left <= r->left &&
+ rect->right >= r->right &&
+ rect->top > r->top &&
+ rect->bottom >= r->bottom)
+ {
+ /* partially covered(bottom) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ }
+ else if (rect->top <= r->top &&
+ rect->bottom >= r->bottom &&
+ rect->left > r->left &&
+ rect->right >= r->right)
+ {
+ /* partially covered(right) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ rect->left, r->bottom);
+ }
+ else if (rect->left <= r->left &&
+ rect->top <= r->top &&
+ rect->right < r->right &&
+ rect->bottom < r->bottom)
+ {
+ /* partially covered(top left) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, rect->right, r->top,
+ r->right, rect->bottom);
+ xrdp_region_insert_rect(self, i, r->left, rect->bottom,
+ r->right, r->bottom);
+ }
+ else if (rect->left <= r->left &&
+ rect->bottom >= r->bottom &&
+ rect->right < r->right &&
+ rect->top > r->top)
+ {
+ /* partially covered(bottom left) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ xrdp_region_insert_rect(self, i, rect->right, rect->top,
+ r->right, r->bottom);
+ }
+ else if (rect->left > r->left &&
+ rect->right >= r->right &&
+ rect->top <= r->top &&
+ rect->bottom < r->bottom)
+ {
+ /* partially covered(top right) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ rect->left, r->bottom);
+ xrdp_region_insert_rect(self, i, rect->left, rect->bottom,
+ r->right, r->bottom);
+ }
+ else if (rect->left > r->left &&
+ rect->right >= r->right &&
+ rect->top > r->top &&
+ rect->bottom >= r->bottom)
+ {
+ /* partially covered(bottom right) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ xrdp_region_insert_rect(self, i, r->left, rect->top,
+ rect->left, r->bottom);
+ }
+ else if (rect->left > r->left &&
+ rect->top <= r->top &&
+ rect->right < r->right &&
+ rect->bottom >= r->bottom)
+ {
+ /* 2 rects, one on each end */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ rect->left, r->bottom);
+ xrdp_region_insert_rect(self, i, rect->right, r->top,
+ r->right, r->bottom);
+ }
+ else if (rect->left <= r->left &&
+ rect->top > r->top &&
+ rect->right >= r->right &&
+ rect->bottom < r->bottom)
+ {
+ /* 2 rects, one on each end */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ xrdp_region_insert_rect(self, i, r->left, rect->bottom,
+ r->right, r->bottom);
+ }
+ else if (rect->left > r->left &&
+ rect->right < r->right &&
+ rect->top <= r->top &&
+ rect->bottom < r->bottom)
+ {
+ /* partially covered(top) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ rect->left, r->bottom);
+ xrdp_region_insert_rect(self, i, rect->left, rect->bottom,
+ rect->right, r->bottom);
+ xrdp_region_insert_rect(self, i, rect->right, r->top,
+ r->right, r->bottom);
+ }
+ else if (rect->top > r->top &&
+ rect->bottom < r->bottom &&
+ rect->left <= r->left &&
+ rect->right < r->right)
+ {
+ /* partially covered(left) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ xrdp_region_insert_rect(self, i, rect->right, rect->top,
+ r->right, rect->bottom);
+ xrdp_region_insert_rect(self, i, r->left, rect->bottom,
+ r->right, r->bottom);
+ }
+ else if (rect->left > r->left &&
+ rect->right < r->right &&
+ rect->bottom >= r->bottom &&
+ rect->top > r->top)
+ {
+ /* partially covered(bottom) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ rect->left, r->bottom);
+ xrdp_region_insert_rect(self, i, rect->left, r->top,
+ rect->right, rect->top);
+ xrdp_region_insert_rect(self, i, rect->right, r->top,
+ r->right, r->bottom);
+ }
+ else if (rect->top > r->top &&
+ rect->bottom < r->bottom &&
+ rect->right >= r->right &&
+ rect->left > r->left)
+ {
+ /* partially covered(right) */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ xrdp_region_insert_rect(self, i, r->left, rect->top,
+ rect->left, rect->bottom);
+ xrdp_region_insert_rect(self, i, r->left, rect->bottom,
+ r->right, r->bottom);
+ }
+ else if (rect->left > r->left &&
+ rect->top > r->top &&
+ rect->right < r->right &&
+ rect->bottom < r->bottom)
+ {
+ /* totally contained, 4 rects */
+ list_remove_item(self->rects, i);
+ xrdp_region_insert_rect(self, i, r->left, r->top,
+ r->right, rect->top);
+ xrdp_region_insert_rect(self, i, r->left, rect->top,
+ rect->left, rect->bottom);
+ xrdp_region_insert_rect(self, i, r->left, rect->bottom,
+ r->right, r->bottom);
+ xrdp_region_insert_rect(self, i, rect->right, rect->top,
+ r->right, rect->bottom);
+ }
+ else
+ {
+ g_writeln("error in xrdp_region_subtract_rect");
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_region_get_rect(struct xrdp_region* self, int index,
- struct xrdp_rect* rect)
+xrdp_region_get_rect(struct xrdp_region *self, int index,
+ struct xrdp_rect *rect)
{
- struct xrdp_rect* r;
+ struct xrdp_rect *r;
+
+ r = (struct xrdp_rect *)list_get_item(self->rects, index);
+
+ if (r == 0)
+ {
+ return 1;
+ }
- r = (struct xrdp_rect*)list_get_item(self->rects, index);
- if (r == 0)
- {
- return 1;
- }
- *rect = *r;
- return 0;
+ *rect = *r;
+ return 0;
}
diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h
index e907e2a0..fdaed059 100644
--- a/xrdp/xrdp_types.h
+++ b/xrdp/xrdp_types.h
@@ -1,24 +1,23 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * types
+ */
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- types
-
-*/
#define DEFAULT_STRING_LEN 255
#define LOG_WINDOW_CHAR_PER_LINE 60
diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c
index 7883d33e..24362f54 100644
--- a/xrdp/xrdp_wm.c
+++ b/xrdp/xrdp_wm.c
@@ -1,1383 +1,1528 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2010
-
- simple window manager
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * simple window manager
+ */
#include "xrdp.h"
/*****************************************************************************/
-struct xrdp_wm* APP_CC
-xrdp_wm_create(struct xrdp_process* owner,
- struct xrdp_client_info* client_info)
+struct xrdp_wm *APP_CC
+xrdp_wm_create(struct xrdp_process *owner,
+ struct xrdp_client_info *client_info)
{
- struct xrdp_wm* self = (struct xrdp_wm *)NULL;
- char event_name[256];
- int pid = 0;
-
- /* initialize (zero out) local variables: */
- g_memset(event_name,0,sizeof(char) * 256);
-
- self = (struct xrdp_wm*)g_malloc(sizeof(struct xrdp_wm), 1);
- self->client_info = client_info;
- self->screen = xrdp_bitmap_create(client_info->width,
- client_info->height,
- client_info->bpp,
- WND_TYPE_SCREEN, self);
- self->screen->wm = self;
- self->pro_layer = owner;
- self->session = owner->session;
- pid = g_getpid();
- g_snprintf(event_name, 255, "xrdp_%8.8x_wm_login_mode_event_%8.8x",
- pid, owner->session_id);
- self->login_mode_event = g_create_wait_obj(event_name);
- self->painter = xrdp_painter_create(self, self->session);
- self->cache = xrdp_cache_create(self, self->session, self->client_info);
- self->log = list_create();
- self->log->auto_free = 1;
- self->mm = xrdp_mm_create(self);
- self->default_font = xrdp_font_create(self);
- /* this will use built in keymap or load from file */
- get_keymaps(self->session->client_info->keylayout, &(self->keymap));
- xrdp_wm_set_login_mode(self, 0);
- self->target_surface = self->screen;
- self->current_surface_index = 0xffff; /* screen */
- return self;
+ struct xrdp_wm *self = (struct xrdp_wm *)NULL;
+ char event_name[256];
+ int pid = 0;
+
+ /* initialize (zero out) local variables: */
+ g_memset(event_name, 0, sizeof(char) * 256);
+
+ self = (struct xrdp_wm *)g_malloc(sizeof(struct xrdp_wm), 1);
+ self->client_info = client_info;
+ self->screen = xrdp_bitmap_create(client_info->width,
+ client_info->height,
+ client_info->bpp,
+ WND_TYPE_SCREEN, self);
+ self->screen->wm = self;
+ self->pro_layer = owner;
+ self->session = owner->session;
+ pid = g_getpid();
+ g_snprintf(event_name, 255, "xrdp_%8.8x_wm_login_mode_event_%8.8x",
+ pid, owner->session_id);
+ self->login_mode_event = g_create_wait_obj(event_name);
+ self->painter = xrdp_painter_create(self, self->session);
+ self->cache = xrdp_cache_create(self, self->session, self->client_info);
+ self->log = list_create();
+ self->log->auto_free = 1;
+ self->mm = xrdp_mm_create(self);
+ self->default_font = xrdp_font_create(self);
+ /* this will use built in keymap or load from file */
+ get_keymaps(self->session->client_info->keylayout, &(self->keymap));
+ xrdp_wm_set_login_mode(self, 0);
+ self->target_surface = self->screen;
+ self->current_surface_index = 0xffff; /* screen */
+ return self;
}
/*****************************************************************************/
void APP_CC
-xrdp_wm_delete(struct xrdp_wm* self)
+xrdp_wm_delete(struct xrdp_wm *self)
{
- if (self == 0)
- {
- return;
- }
- xrdp_mm_delete(self->mm);
- xrdp_cache_delete(self->cache);
- xrdp_painter_delete(self->painter);
- xrdp_bitmap_delete(self->screen);
- /* free the log */
- list_delete(self->log);
- /* free default font */
- xrdp_font_delete(self->default_font);
- g_delete_wait_obj(self->login_mode_event);
- /* free self */
- g_free(self);
+ if (self == 0)
+ {
+ return;
+ }
+
+ xrdp_mm_delete(self->mm);
+ xrdp_cache_delete(self->cache);
+ xrdp_painter_delete(self->painter);
+ xrdp_bitmap_delete(self->screen);
+ /* free the log */
+ list_delete(self->log);
+ /* free default font */
+ xrdp_font_delete(self->default_font);
+ g_delete_wait_obj(self->login_mode_event);
+ /* free self */
+ g_free(self);
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_send_palette(struct xrdp_wm* self)
+xrdp_wm_send_palette(struct xrdp_wm *self)
{
- return libxrdp_send_palette(self->session, self->palette);
+ return libxrdp_send_palette(self->session, self->palette);
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_send_bell(struct xrdp_wm* self)
+xrdp_wm_send_bell(struct xrdp_wm *self)
{
- return libxrdp_send_bell(self->session);
+ return libxrdp_send_bell(self->session);
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_send_bitmap(struct xrdp_wm* self, struct xrdp_bitmap* bitmap,
+xrdp_wm_send_bitmap(struct xrdp_wm *self, struct xrdp_bitmap *bitmap,
int x, int y, int cx, int cy)
{
- return libxrdp_send_bitmap(self->session, bitmap->width, bitmap->height,
- bitmap->bpp, bitmap->data, x, y, cx, cy);
+ return libxrdp_send_bitmap(self->session, bitmap->width, bitmap->height,
+ bitmap->bpp, bitmap->data, x, y, cx, cy);
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_set_focused(struct xrdp_wm* self, struct xrdp_bitmap* wnd)
+xrdp_wm_set_focused(struct xrdp_wm *self, struct xrdp_bitmap *wnd)
{
- struct xrdp_bitmap* focus_out_control;
- struct xrdp_bitmap* focus_in_control;
+ struct xrdp_bitmap *focus_out_control;
+ struct xrdp_bitmap *focus_in_control;
- if (self == 0)
- {
- return 0;
- }
- if (self->focused_window == wnd)
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (self->focused_window == wnd)
+ {
+ return 0;
+ }
+
+ focus_out_control = 0;
+ focus_in_control = 0;
+
+ if (self->focused_window != 0)
+ {
+ xrdp_bitmap_set_focus(self->focused_window, 0);
+ focus_out_control = self->focused_window->focused_control;
+ }
+
+ self->focused_window = wnd;
+
+ if (self->focused_window != 0)
+ {
+ xrdp_bitmap_set_focus(self->focused_window, 1);
+ focus_in_control = self->focused_window->focused_control;
+ }
+
+ xrdp_bitmap_invalidate(focus_out_control, 0);
+ xrdp_bitmap_invalidate(focus_in_control, 0);
return 0;
- }
- focus_out_control = 0;
- focus_in_control = 0;
- if (self->focused_window != 0)
- {
- xrdp_bitmap_set_focus(self->focused_window, 0);
- focus_out_control = self->focused_window->focused_control;
- }
- self->focused_window = wnd;
- if (self->focused_window != 0)
- {
- xrdp_bitmap_set_focus(self->focused_window, 1);
- focus_in_control = self->focused_window->focused_control;
- }
- xrdp_bitmap_invalidate(focus_out_control, 0);
- xrdp_bitmap_invalidate(focus_in_control, 0);
- return 0;
}
/******************************************************************************/
static int APP_CC
-xrdp_wm_get_pixel(char* data, int x, int y, int width, int bpp)
+xrdp_wm_get_pixel(char *data, int x, int y, int width, int bpp)
{
- int start;
- int shift;
-
- if (bpp == 1)
- {
- width = (width + 7) / 8;
- start = (y * width) + x / 8;
- shift = x % 8;
- return (data[start] & (0x80 >> shift)) != 0;
- }
- else if (bpp == 4)
- {
- width = (width + 1) / 2;
- start = y * width + x / 2;
- shift = x % 2;
- if (shift == 0)
- {
- return (data[start] & 0xf0) >> 4;
+ int start;
+ int shift;
+
+ if (bpp == 1)
+ {
+ width = (width + 7) / 8;
+ start = (y * width) + x / 8;
+ shift = x % 8;
+ return (data[start] & (0x80 >> shift)) != 0;
}
- else
+ else if (bpp == 4)
{
- return data[start] & 0x0f;
+ width = (width + 1) / 2;
+ start = y * width + x / 2;
+ shift = x % 2;
+
+ if (shift == 0)
+ {
+ return (data[start] & 0xf0) >> 4;
+ }
+ else
+ {
+ return data[start] & 0x0f;
+ }
}
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_pointer(struct xrdp_wm* self, char* data, char* mask, int x, int y)
+xrdp_wm_pointer(struct xrdp_wm *self, char *data, char *mask, int x, int y)
{
- struct xrdp_pointer_item pointer_item;
-
- g_memset(&pointer_item, 0, sizeof(struct xrdp_pointer_item));
- pointer_item.x = x;
- pointer_item.y = y;
- g_memcpy(pointer_item.data, data, 32 * 32 * 3);
- g_memcpy(pointer_item.mask, mask, 32 * 32 / 8);
- self->screen->pointer = xrdp_cache_add_pointer(self->cache, &pointer_item);
- return 0;
+ struct xrdp_pointer_item pointer_item;
+
+ g_memset(&pointer_item, 0, sizeof(struct xrdp_pointer_item));
+ pointer_item.x = x;
+ pointer_item.y = y;
+ g_memcpy(pointer_item.data, data, 32 * 32 * 3);
+ g_memcpy(pointer_item.mask, mask, 32 * 32 / 8);
+ self->screen->pointer = xrdp_cache_add_pointer(self->cache, &pointer_item);
+ return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
-xrdp_wm_load_pointer(struct xrdp_wm* self, char* file_name, char* data,
- char* mask, int* x, int* y)
+xrdp_wm_load_pointer(struct xrdp_wm *self, char *file_name, char *data,
+ char *mask, int *x, int *y)
{
- int fd;
- int bpp;
- int w;
- int h;
- int i;
- int j;
- int pixel;
- int palette[16];
- struct stream* fs;
-
- if (!g_file_exist(file_name))
- {
- g_writeln("xrdp_wm_load_pointer: error pointer file [%s] does not exist",
- file_name);
- return 1;
- }
- make_stream(fs);
- init_stream(fs, 8192);
- fd = g_file_open(file_name);
- if (fd < 1)
- {
- g_writeln("xrdp_wm_load_pointer: error loading pointer from file [%s]",
- file_name);
- return 1;
- }
- g_file_read(fd, fs->data, 8192);
- g_file_close(fd);
- in_uint8s(fs, 6);
- in_uint8(fs, w);
- in_uint8(fs, h);
- in_uint8s(fs, 2);
- in_uint16_le(fs, *x);
- in_uint16_le(fs, *y);
- in_uint8s(fs, 22);
- in_uint8(fs, bpp);
- in_uint8s(fs, 25);
- if (w == 32 && h == 32)
- {
- if (bpp == 1)
+ int fd;
+ int bpp;
+ int w;
+ int h;
+ int i;
+ int j;
+ int pixel;
+ int palette[16];
+ struct stream *fs;
+
+ if (!g_file_exist(file_name))
{
- in_uint8a(fs, palette, 8);
- for (i = 0; i < 32; i++)
- {
- for (j = 0; j < 32; j++)
- {
- pixel = palette[xrdp_wm_get_pixel(fs->p, j, i, 32, 1)];
- *data = pixel;
- data++;
- *data = pixel >> 8;
- data++;
- *data = pixel >> 16;
- data++;
- }
- }
- in_uint8s(fs, 128);
+ g_writeln("xrdp_wm_load_pointer: error pointer file [%s] does not exist",
+ file_name);
+ return 1;
}
- else if (bpp == 4)
+
+ make_stream(fs);
+ init_stream(fs, 8192);
+ fd = g_file_open(file_name);
+
+ if (fd < 1)
+ {
+ g_writeln("xrdp_wm_load_pointer: error loading pointer from file [%s]",
+ file_name);
+ return 1;
+ }
+
+ g_file_read(fd, fs->data, 8192);
+ g_file_close(fd);
+ in_uint8s(fs, 6);
+ in_uint8(fs, w);
+ in_uint8(fs, h);
+ in_uint8s(fs, 2);
+ in_uint16_le(fs, *x);
+ in_uint16_le(fs, *y);
+ in_uint8s(fs, 22);
+ in_uint8(fs, bpp);
+ in_uint8s(fs, 25);
+
+ if (w == 32 && h == 32)
{
- in_uint8a(fs, palette, 64);
- for (i = 0; i < 32; i++)
- {
- for (j = 0; j < 32; j++)
+ if (bpp == 1)
{
- pixel = palette[xrdp_wm_get_pixel(fs->p, j, i, 32, 1)];
- *data = pixel;
- data++;
- *data = pixel >> 8;
- data++;
- *data = pixel >> 16;
- data++;
+ in_uint8a(fs, palette, 8);
+
+ for (i = 0; i < 32; i++)
+ {
+ for (j = 0; j < 32; j++)
+ {
+ pixel = palette[xrdp_wm_get_pixel(fs->p, j, i, 32, 1)];
+ *data = pixel;
+ data++;
+ *data = pixel >> 8;
+ data++;
+ *data = pixel >> 16;
+ data++;
+ }
+ }
+
+ in_uint8s(fs, 128);
}
- }
- in_uint8s(fs, 512);
+ else if (bpp == 4)
+ {
+ in_uint8a(fs, palette, 64);
+
+ for (i = 0; i < 32; i++)
+ {
+ for (j = 0; j < 32; j++)
+ {
+ pixel = palette[xrdp_wm_get_pixel(fs->p, j, i, 32, 1)];
+ *data = pixel;
+ data++;
+ *data = pixel >> 8;
+ data++;
+ *data = pixel >> 16;
+ data++;
+ }
+ }
+
+ in_uint8s(fs, 512);
+ }
+
+ g_memcpy(mask, fs->p, 128); /* mask */
}
- g_memcpy(mask, fs->p, 128); /* mask */
- }
- free_stream(fs);
- return 0;
+
+ free_stream(fs);
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_send_pointer(struct xrdp_wm* self, int cache_idx,
- char* data, char* mask, int x, int y)
+xrdp_wm_send_pointer(struct xrdp_wm *self, int cache_idx,
+ char *data, char *mask, int x, int y)
{
- return libxrdp_send_pointer(self->session, cache_idx, data, mask, x, y);
+ return libxrdp_send_pointer(self->session, cache_idx, data, mask, x, y);
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_set_pointer(struct xrdp_wm* self, int cache_idx)
+xrdp_wm_set_pointer(struct xrdp_wm *self, int cache_idx)
{
- return libxrdp_set_pointer(self->session, cache_idx);
+ return libxrdp_set_pointer(self->session, cache_idx);
}
/*****************************************************************************/
/* convert hex string to int */
unsigned int xrdp_wm_htoi (const char *ptr)
{
- unsigned int value = 0;
- char ch = *ptr;
-
- while (ch == ' ' || ch == '\t')
- ch = *(++ptr);
-
- for (;;)
- {
- if (ch >= '0' && ch <= '9')
- value = (value << 4) + (ch - '0');
- else if (ch >= 'A' && ch <= 'F')
- value = (value << 4) + (ch - 'A' + 10);
- else if (ch >= 'a' && ch <= 'f')
- value = (value << 4) + (ch - 'a' + 10);
- else
- return value;
- ch = *(++ptr);
- }
+ unsigned int value = 0;
+ char ch = *ptr;
+
+ while (ch == ' ' || ch == '\t')
+ {
+ ch = *(++ptr);
+ }
+
+ for (;;)
+ {
+ if (ch >= '0' && ch <= '9')
+ {
+ value = (value << 4) + (ch - '0');
+ }
+ else if (ch >= 'A' && ch <= 'F')
+ {
+ value = (value << 4) + (ch - 'A' + 10);
+ }
+ else if (ch >= 'a' && ch <= 'f')
+ {
+ value = (value << 4) + (ch - 'a' + 10);
+ }
+ else
+ {
+ return value;
+ }
+
+ ch = *(++ptr);
+ }
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_load_static_colors_plus(struct xrdp_wm* self, char* autorun_name)
+xrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name)
{
- int bindex;
- int gindex;
- int rindex;
-
- int fd;
- int index;
- char* val;
- struct list* names;
- struct list* values;
- char cfg_file[256];
-
- if (autorun_name != 0)
- {
- autorun_name[0] = 0;
- }
-
- /* initialize with defaults */
- self->black = HCOLOR(self->screen->bpp,0x000000);
- self->grey = HCOLOR(self->screen->bpp,0xc0c0c0);
- self->dark_grey = HCOLOR(self->screen->bpp,0x808080);
- self->blue = HCOLOR(self->screen->bpp,0x0000ff);
- self->dark_blue = HCOLOR(self->screen->bpp,0x00007f);
- self->white = HCOLOR(self->screen->bpp,0xffffff);
- self->red = HCOLOR(self->screen->bpp,0xff0000);
- self->green = HCOLOR(self->screen->bpp,0x00ff00);
- self->background = HCOLOR(self->screen->bpp,0x000000);
-
- /* now load them from the globals in xrdp.ini if defined */
- g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
- fd = g_file_open(cfg_file);
- if (fd > 0)
- {
- names = list_create();
- names->auto_free = 1;
- values = list_create();
- values->auto_free = 1;
- if (file_read_section(fd, "globals", names, values) == 0)
- {
- for (index = 0; index < names->count; index++)
- {
- val = (char*)list_get_item(names, index);
- if (val != 0)
+ int bindex;
+ int gindex;
+ int rindex;
+
+ int fd;
+ int index;
+ char *val;
+ struct list *names;
+ struct list *values;
+ char cfg_file[256];
+
+ if (autorun_name != 0)
+ {
+ autorun_name[0] = 0;
+ }
+
+ /* initialize with defaults */
+ self->black = HCOLOR(self->screen->bpp, 0x000000);
+ self->grey = HCOLOR(self->screen->bpp, 0xc0c0c0);
+ self->dark_grey = HCOLOR(self->screen->bpp, 0x808080);
+ self->blue = HCOLOR(self->screen->bpp, 0x0000ff);
+ self->dark_blue = HCOLOR(self->screen->bpp, 0x00007f);
+ self->white = HCOLOR(self->screen->bpp, 0xffffff);
+ self->red = HCOLOR(self->screen->bpp, 0xff0000);
+ self->green = HCOLOR(self->screen->bpp, 0x00ff00);
+ self->background = HCOLOR(self->screen->bpp, 0x000000);
+
+ /* now load them from the globals in xrdp.ini if defined */
+ g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+ fd = g_file_open(cfg_file);
+
+ if (fd > 0)
+ {
+ names = list_create();
+ names->auto_free = 1;
+ values = list_create();
+ values->auto_free = 1;
+
+ if (file_read_section(fd, "globals", names, values) == 0)
{
- if (g_strcasecmp(val, "black") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->black = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "grey") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->grey = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "dark_grey") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->dark_grey = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "blue") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->blue = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "dark_blue") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->dark_blue = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "white") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->white = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "red") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->red = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "green") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->green = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "background") == 0)
- {
- val = (char*)list_get_item(values, index);
- self->background = HCOLOR(self->screen->bpp,xrdp_wm_htoi(val));
- }
- else if (g_strcasecmp(val, "autorun") == 0)
- {
- val = (char*)list_get_item(values, index);
- if (autorun_name != 0)
+ for (index = 0; index < names->count; index++)
{
- g_strncpy(autorun_name, val, 255);
+ val = (char *)list_get_item(names, index);
+
+ if (val != 0)
+ {
+ if (g_strcasecmp(val, "black") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->black = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "grey") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->grey = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "dark_grey") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->dark_grey = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "blue") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->blue = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "dark_blue") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->dark_blue = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "white") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->white = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "red") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->red = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "green") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->green = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "background") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+ self->background = HCOLOR(self->screen->bpp, xrdp_wm_htoi(val));
+ }
+ else if (g_strcasecmp(val, "autorun") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+
+ if (autorun_name != 0)
+ {
+ g_strncpy(autorun_name, val, 255);
+ }
+ }
+ else if (g_strcasecmp(val, "hidelogwindow") == 0)
+ {
+ val = (char *)list_get_item(values, index);
+
+ if ((g_strcasecmp(val, "yes") == 0) ||
+ (g_strcasecmp(val, "1") == 0) ||
+ (g_strcasecmp(val, "true") == 0))
+ {
+ self->hide_log_window = 1;
+ }
+ }
+ }
}
- }
- else if (g_strcasecmp(val, "hidelogwindow") == 0)
- {
- val = (char*)list_get_item(values, index);
- if ((g_strcasecmp(val, "yes") == 0) ||
- (g_strcasecmp(val, "1") == 0) ||
- (g_strcasecmp(val, "true") == 0))
- {
- self->hide_log_window = 1;
- }
- }
}
- }
+
+ list_delete(names);
+ list_delete(values);
+ g_file_close(fd);
}
- list_delete(names);
- list_delete(values);
- g_file_close(fd);
- }
- else
- {
- g_writeln("xrdp_wm_load_static_colors: Could not read xrdp.ini file %s", cfg_file);
- }
-
- if (self->screen->bpp == 8)
- {
- /* rgb332 */
- for (bindex = 0; bindex < 4; bindex++)
- {
- for (gindex = 0; gindex < 8; gindex++)
- {
- for (rindex = 0; rindex < 8; rindex++)
+ else
+ {
+ g_writeln("xrdp_wm_load_static_colors: Could not read xrdp.ini file %s", cfg_file);
+ }
+
+ if (self->screen->bpp == 8)
+ {
+ /* rgb332 */
+ for (bindex = 0; bindex < 4; bindex++)
{
- self->palette[(bindex << 6) | (gindex << 3) | rindex] =
- (((rindex << 5) | (rindex << 2) | (rindex >> 1)) << 16) |
- (((gindex << 5) | (gindex << 2) | (gindex >> 1)) << 8) |
- ((bindex << 6) | (bindex << 4) | (bindex << 2) | (bindex));
+ for (gindex = 0; gindex < 8; gindex++)
+ {
+ for (rindex = 0; rindex < 8; rindex++)
+ {
+ self->palette[(bindex << 6) | (gindex << 3) | rindex] =
+ (((rindex << 5) | (rindex << 2) | (rindex >> 1)) << 16) |
+ (((gindex << 5) | (gindex << 2) | (gindex >> 1)) << 8) |
+ ((bindex << 6) | (bindex << 4) | (bindex << 2) | (bindex));
+ }
+ }
}
- }
+
+ xrdp_wm_send_palette(self);
}
- xrdp_wm_send_palette(self);
- }
- return 0;
+
+ return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
-xrdp_wm_load_static_pointers(struct xrdp_wm* self)
+xrdp_wm_load_static_pointers(struct xrdp_wm *self)
{
- struct xrdp_pointer_item pointer_item;
- char file_path[256];
-
- DEBUG(("sending cursor"));
- g_snprintf(file_path, 255, "%s/cursor1.cur", XRDP_SHARE_PATH);
- g_memset(&pointer_item, 0, sizeof(pointer_item));
- xrdp_wm_load_pointer(self, file_path, pointer_item.data,
- pointer_item.mask, &pointer_item.x, &pointer_item.y);
- xrdp_cache_add_pointer_static(self->cache, &pointer_item, 1);
- DEBUG(("sending cursor"));
- g_snprintf(file_path, 255, "%s/cursor0.cur", XRDP_SHARE_PATH);
- g_memset(&pointer_item, 0, sizeof(pointer_item));
- xrdp_wm_load_pointer(self, file_path, pointer_item.data,
- pointer_item.mask, &pointer_item.x, &pointer_item.y);
- xrdp_cache_add_pointer_static(self->cache, &pointer_item, 0);
- return 0;
+ struct xrdp_pointer_item pointer_item;
+ char file_path[256];
+
+ DEBUG(("sending cursor"));
+ g_snprintf(file_path, 255, "%s/cursor1.cur", XRDP_SHARE_PATH);
+ g_memset(&pointer_item, 0, sizeof(pointer_item));
+ xrdp_wm_load_pointer(self, file_path, pointer_item.data,
+ pointer_item.mask, &pointer_item.x, &pointer_item.y);
+ xrdp_cache_add_pointer_static(self->cache, &pointer_item, 1);
+ DEBUG(("sending cursor"));
+ g_snprintf(file_path, 255, "%s/cursor0.cur", XRDP_SHARE_PATH);
+ g_memset(&pointer_item, 0, sizeof(pointer_item));
+ xrdp_wm_load_pointer(self, file_path, pointer_item.data,
+ pointer_item.mask, &pointer_item.x, &pointer_item.y);
+ xrdp_cache_add_pointer_static(self->cache, &pointer_item, 0);
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_init(struct xrdp_wm* self)
+xrdp_wm_init(struct xrdp_wm *self)
{
- int fd;
- int index;
- struct list* names;
- struct list* values;
- char* q;
- char* r;
- char section_name[256];
- char cfg_file[256];
- char autorun_name[256];
-
- xrdp_wm_load_static_colors_plus(self, autorun_name);
- xrdp_wm_load_static_pointers(self);
- self->screen->bg_color = self->background;
- if (self->session->client_info->rdp_autologin || (autorun_name[0] != 0))
- {
- g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
- fd = g_file_open(cfg_file); /* xrdp.ini */
- if (fd > 0)
+ int fd;
+ int index;
+ struct list *names;
+ struct list *values;
+ char *q;
+ char *r;
+ char section_name[256];
+ char cfg_file[256];
+ char autorun_name[256];
+
+ xrdp_wm_load_static_colors_plus(self, autorun_name);
+ xrdp_wm_load_static_pointers(self);
+ self->screen->bg_color = self->background;
+
+ if (self->session->client_info->rdp_autologin || (autorun_name[0] != 0))
{
- names = list_create();
- names->auto_free = 1;
- values = list_create();
- values->auto_free = 1;
- g_strncpy(section_name, self->session->client_info->domain, 255);
- if (section_name[0] == 0)
- {
- if (autorun_name[0] == 0)
+ g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
+ fd = g_file_open(cfg_file); /* xrdp.ini */
+
+ if (fd > 0)
{
- /* if no doamin is passed, and no autorun in xrdp.ini,
- use the first item in the xrdp.ini
- file thats not named 'globals' */
- file_read_sections(fd, names);
- for (index = 0; index < names->count; index++)
- {
- q = (char*)list_get_item(names, index);
- if (g_strncasecmp("globals", q, 8) != 0)
+ names = list_create();
+ names->auto_free = 1;
+ values = list_create();
+ values->auto_free = 1;
+ g_strncpy(section_name, self->session->client_info->domain, 255);
+
+ if (section_name[0] == 0)
{
- g_strncpy(section_name, q, 255);
- break;
+ if (autorun_name[0] == 0)
+ {
+ /* if no doamin is passed, and no autorun in xrdp.ini,
+ use the first item in the xrdp.ini
+ file thats not named 'globals' */
+ file_read_sections(fd, names);
+
+ for (index = 0; index < names->count; index++)
+ {
+ q = (char *)list_get_item(names, index);
+
+ if (g_strncasecmp("globals", q, 8) != 0)
+ {
+ g_strncpy(section_name, q, 255);
+ break;
+ }
+ }
+ }
+ else
+ {
+ g_strncpy(section_name, autorun_name, 255);
+ }
}
- }
+
+ list_clear(names);
+
+ if (file_read_section(fd, section_name, names, values) == 0)
+ {
+ for (index = 0; index < names->count; index++)
+ {
+ q = (char *)list_get_item(names, index);
+ r = (char *)list_get_item(values, index);
+
+ if (g_strncmp("password", q, 255) == 0)
+ {
+ /* if the password has been asked for by the module, use what the
+ client says.
+ if the password has been manually set in the config, use that
+ instead of what the client says. */
+ if (g_strncmp("ask", r, 3) == 0)
+ {
+ r = self->session->client_info->password;
+ }
+ }
+ else if (g_strncmp("username", q, 255) == 0)
+ {
+ /* if the username has been asked for by the module, use what the
+ client says.
+ if the username has been manually set in the config, use that
+ instead of what the client says. */
+ if (g_strncmp("ask", r, 3) == 0)
+ {
+ r = self->session->client_info->username;
+ }
+ }
+
+ list_add_item(self->mm->login_names, (long)g_strdup(q));
+ list_add_item(self->mm->login_values, (long)g_strdup(r));
+ }
+
+ xrdp_wm_set_login_mode(self, 2);
+ }
+
+ list_delete(names);
+ list_delete(values);
+ g_file_close(fd);
}
else
{
- g_strncpy(section_name, autorun_name, 255);
- }
- }
- list_clear(names);
- if (file_read_section(fd, section_name, names, values) == 0)
- {
- for (index = 0; index < names->count; index++)
- {
- q = (char*)list_get_item(names, index);
- r = (char*)list_get_item(values, index);
- if (g_strncmp("password", q, 255) == 0)
- {
- /* if the password has been asked for by the module, use what the
- client says.
- if the password has been manually set in the config, use that
- instead of what the client says. */
- if (g_strncmp("ask", r, 3) == 0)
- {
- r = self->session->client_info->password;
- }
- }
- else if (g_strncmp("username", q, 255) == 0)
- {
- /* if the username has been asked for by the module, use what the
- client says.
- if the username has been manually set in the config, use that
- instead of what the client says. */
- if (g_strncmp("ask", r, 3) == 0)
- {
- r = self->session->client_info->username;
- }
- }
- list_add_item(self->mm->login_names, (long)g_strdup(q));
- list_add_item(self->mm->login_values, (long)g_strdup(r));
+ g_writeln("xrdp_wm_init: Could not read xrdp.ini file %s", cfg_file);
}
- xrdp_wm_set_login_mode(self, 2);
- }
- list_delete(names);
- list_delete(values);
- g_file_close(fd);
}
else
{
- g_writeln("xrdp_wm_init: Could not read xrdp.ini file %s", cfg_file);
- }
- }
- else
- {
- xrdp_login_wnd_create(self);
- /* clear screen */
- xrdp_bitmap_invalidate(self->screen, 0);
- xrdp_wm_set_focused(self, self->login_window);
- xrdp_wm_set_login_mode(self, 1);
- }
- return 0;
+ xrdp_login_wnd_create(self);
+ /* clear screen */
+ xrdp_bitmap_invalidate(self->screen, 0);
+ xrdp_wm_set_focused(self, self->login_window);
+ xrdp_wm_set_login_mode(self, 1);
+ }
+
+ return 0;
}
/*****************************************************************************/
/* returns the number for rects visible for an area relative to a drawable */
/* putting the rects in region */
int APP_CC
-xrdp_wm_get_vis_region(struct xrdp_wm* self, struct xrdp_bitmap* bitmap,
+xrdp_wm_get_vis_region(struct xrdp_wm *self, struct xrdp_bitmap *bitmap,
int x, int y, int cx, int cy,
- struct xrdp_region* region, int clip_children)
+ struct xrdp_region *region, int clip_children)
{
- int i;
- struct xrdp_bitmap* p;
- struct xrdp_rect a;
- struct xrdp_rect b;
-
- /* area we are drawing */
- MAKERECT(a, bitmap->left + x, bitmap->top + y, cx, cy);
- p = bitmap->parent;
- while (p != 0)
- {
- RECTOFFSET(a, p->left, p->top);
- p = p->parent;
- }
- a.left = MAX(self->screen->left, a.left);
- a.top = MAX(self->screen->top, a.top);
- a.right = MIN(self->screen->left + self->screen->width, a.right);
- a.bottom = MIN(self->screen->top + self->screen->height, a.bottom);
- xrdp_region_add_rect(region, &a);
- if (clip_children)
- {
- /* loop through all windows in z order */
- for (i = 0; i < self->screen->child_list->count; i++)
+ int i;
+ struct xrdp_bitmap *p;
+ struct xrdp_rect a;
+ struct xrdp_rect b;
+
+ /* area we are drawing */
+ MAKERECT(a, bitmap->left + x, bitmap->top + y, cx, cy);
+ p = bitmap->parent;
+
+ while (p != 0)
{
- p = (struct xrdp_bitmap*)list_get_item(self->screen->child_list, i);
- if (p == bitmap || p == bitmap->parent)
- {
- return 0;
- }
- MAKERECT(b, p->left, p->top, p->width, p->height);
- xrdp_region_subtract_rect(region, &b);
+ RECTOFFSET(a, p->left, p->top);
+ p = p->parent;
}
- }
- return 0;
+
+ a.left = MAX(self->screen->left, a.left);
+ a.top = MAX(self->screen->top, a.top);
+ a.right = MIN(self->screen->left + self->screen->width, a.right);
+ a.bottom = MIN(self->screen->top + self->screen->height, a.bottom);
+ xrdp_region_add_rect(region, &a);
+
+ if (clip_children)
+ {
+ /* loop through all windows in z order */
+ for (i = 0; i < self->screen->child_list->count; i++)
+ {
+ p = (struct xrdp_bitmap *)list_get_item(self->screen->child_list, i);
+
+ if (p == bitmap || p == bitmap->parent)
+ {
+ return 0;
+ }
+
+ MAKERECT(b, p->left, p->top, p->width, p->height);
+ xrdp_region_subtract_rect(region, &b);
+ }
+ }
+
+ return 0;
}
/*****************************************************************************/
/* return the window at x, y on the screen */
-static struct xrdp_bitmap* APP_CC
-xrdp_wm_at_pos(struct xrdp_bitmap* wnd, int x, int y,
- struct xrdp_bitmap** wnd1)
+static struct xrdp_bitmap *APP_CC
+xrdp_wm_at_pos(struct xrdp_bitmap *wnd, int x, int y,
+ struct xrdp_bitmap **wnd1)
{
- int i;
- struct xrdp_bitmap* p;
- struct xrdp_bitmap* q;
-
- /* loop through all windows in z order */
- for (i = 0; i < wnd->child_list->count; i++)
- {
- p = (struct xrdp_bitmap*)list_get_item(wnd->child_list, i);
- if (x >= p->left && y >= p->top && x < p->left + p->width &&
- y < p->top + p->height)
- {
- if (wnd1 != 0)
- {
- *wnd1 = p;
- }
- q = xrdp_wm_at_pos(p, x - p->left, y - p->top, 0);
- if (q == 0)
- {
- return p;
- }
- else
- {
- return q;
- }
- }
- }
- return 0;
+ int i;
+ struct xrdp_bitmap *p;
+ struct xrdp_bitmap *q;
+
+ /* loop through all windows in z order */
+ for (i = 0; i < wnd->child_list->count; i++)
+ {
+ p = (struct xrdp_bitmap *)list_get_item(wnd->child_list, i);
+
+ if (x >= p->left && y >= p->top && x < p->left + p->width &&
+ y < p->top + p->height)
+ {
+ if (wnd1 != 0)
+ {
+ *wnd1 = p;
+ }
+
+ q = xrdp_wm_at_pos(p, x - p->left, y - p->top, 0);
+
+ if (q == 0)
+ {
+ return p;
+ }
+ else
+ {
+ return q;
+ }
+ }
+ }
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_xor_pat(struct xrdp_wm* self, int x, int y, int cx, int cy)
+xrdp_wm_xor_pat(struct xrdp_wm *self, int x, int y, int cx, int cy)
{
- self->painter->clip_children = 0;
- self->painter->rop = 0x5a;
- xrdp_painter_begin_update(self->painter);
- self->painter->use_clip = 0;
- self->painter->mix_mode = 1;
- self->painter->brush.pattern[0] = 0xaa;
- self->painter->brush.pattern[1] = 0x55;
- self->painter->brush.pattern[2] = 0xaa;
- self->painter->brush.pattern[3] = 0x55;
- self->painter->brush.pattern[4] = 0xaa;
- self->painter->brush.pattern[5] = 0x55;
- self->painter->brush.pattern[6] = 0xaa;
- self->painter->brush.pattern[7] = 0x55;
- self->painter->brush.x_orgin = 0;
- self->painter->brush.x_orgin = 0;
- self->painter->brush.style = 3;
- self->painter->bg_color = self->black;
- self->painter->fg_color = self->white;
- /* top */
- xrdp_painter_fill_rect(self->painter, self->screen, x, y, cx, 5);
- /* bottom */
- xrdp_painter_fill_rect(self->painter, self->screen, x, y + (cy - 5), cx, 5);
- /* left */
- xrdp_painter_fill_rect(self->painter, self->screen, x, y + 5, 5, cy - 10);
- /* right */
- xrdp_painter_fill_rect(self->painter, self->screen, x + (cx - 5), y + 5, 5,
- cy - 10);
- xrdp_painter_end_update(self->painter);
- self->painter->rop = 0xcc;
- self->painter->clip_children = 1;
- self->painter->mix_mode = 0;
- return 0;
+ self->painter->clip_children = 0;
+ self->painter->rop = 0x5a;
+ xrdp_painter_begin_update(self->painter);
+ self->painter->use_clip = 0;
+ self->painter->mix_mode = 1;
+ self->painter->brush.pattern[0] = 0xaa;
+ self->painter->brush.pattern[1] = 0x55;
+ self->painter->brush.pattern[2] = 0xaa;
+ self->painter->brush.pattern[3] = 0x55;
+ self->painter->brush.pattern[4] = 0xaa;
+ self->painter->brush.pattern[5] = 0x55;
+ self->painter->brush.pattern[6] = 0xaa;
+ self->painter->brush.pattern[7] = 0x55;
+ self->painter->brush.x_orgin = 0;
+ self->painter->brush.x_orgin = 0;
+ self->painter->brush.style = 3;
+ self->painter->bg_color = self->black;
+ self->painter->fg_color = self->white;
+ /* top */
+ xrdp_painter_fill_rect(self->painter, self->screen, x, y, cx, 5);
+ /* bottom */
+ xrdp_painter_fill_rect(self->painter, self->screen, x, y + (cy - 5), cx, 5);
+ /* left */
+ xrdp_painter_fill_rect(self->painter, self->screen, x, y + 5, 5, cy - 10);
+ /* right */
+ xrdp_painter_fill_rect(self->painter, self->screen, x + (cx - 5), y + 5, 5,
+ cy - 10);
+ xrdp_painter_end_update(self->painter);
+ self->painter->rop = 0xcc;
+ self->painter->clip_children = 1;
+ self->painter->mix_mode = 0;
+ return 0;
}
/*****************************************************************************/
/* this don't are about nothing, just copy the bits */
/* no clipping rects, no windows in the way, nothing */
static int APP_CC
-xrdp_wm_bitblt(struct xrdp_wm* self,
- struct xrdp_bitmap* dst, int dx, int dy,
- struct xrdp_bitmap* src, int sx, int sy,
+xrdp_wm_bitblt(struct xrdp_wm *self,
+ struct xrdp_bitmap *dst, int dx, int dy,
+ struct xrdp_bitmap *src, int sx, int sy,
int sw, int sh, int rop)
{
-// int i;
-// int line_size;
-// int Bpp;
-// char* s;
-// char* d;
-
-// if (sw <= 0 || sh <= 0)
-// return 0;
- if (self->screen == dst && self->screen == src)
- { /* send a screen blt */
-// Bpp = (dst->bpp + 7) / 8;
-// line_size = sw * Bpp;
-// s = src->data + (sy * src->width + sx) * Bpp;
-// d = dst->data + (dy * dst->width + dx) * Bpp;
-// for (i = 0; i < sh; i++)
-// {
-// //g_memcpy(d, s, line_size);
-// s += src->width * Bpp;
-// d += dst->width * Bpp;
-// }
- libxrdp_orders_init(self->session);
- libxrdp_orders_screen_blt(self->session, dx, dy, sw, sh, sx, sy, rop, 0);
- libxrdp_orders_send(self->session);
- }
- return 0;
+ // int i;
+ // int line_size;
+ // int Bpp;
+ // char* s;
+ // char* d;
+
+ // if (sw <= 0 || sh <= 0)
+ // return 0;
+ if (self->screen == dst && self->screen == src)
+ {
+ /* send a screen blt */
+ // Bpp = (dst->bpp + 7) / 8;
+ // line_size = sw * Bpp;
+ // s = src->data + (sy * src->width + sx) * Bpp;
+ // d = dst->data + (dy * dst->width + dx) * Bpp;
+ // for (i = 0; i < sh; i++)
+ // {
+ // //g_memcpy(d, s, line_size);
+ // s += src->width * Bpp;
+ // d += dst->width * Bpp;
+ // }
+ libxrdp_orders_init(self->session);
+ libxrdp_orders_screen_blt(self->session, dx, dy, sw, sh, sx, sy, rop, 0);
+ libxrdp_orders_send(self->session);
+ }
+
+ return 0;
}
/*****************************************************************************/
/* return true is rect is totaly exposed going in reverse z order */
/* from wnd up */
static int APP_CC
-xrdp_wm_is_rect_vis(struct xrdp_wm* self, struct xrdp_bitmap* wnd,
- struct xrdp_rect* rect)
+xrdp_wm_is_rect_vis(struct xrdp_wm *self, struct xrdp_bitmap *wnd,
+ struct xrdp_rect *rect)
{
- struct xrdp_rect wnd_rect;
- struct xrdp_bitmap* b;
- int i;;
+ struct xrdp_rect wnd_rect;
+ struct xrdp_bitmap *b;
+ int i;;
- /* if rect is part off screen */
- if (rect->left < 0)
- {
- return 0;
- }
- if (rect->top < 0)
- {
- return 0;
- }
- if (rect->right >= self->screen->width)
- {
- return 0;
- }
- if (rect->bottom >= self->screen->height)
- {
- return 0;
- }
+ /* if rect is part off screen */
+ if (rect->left < 0)
+ {
+ return 0;
+ }
- i = list_index_of(self->screen->child_list, (long)wnd);
- i--;
- while (i >= 0)
- {
- b = (struct xrdp_bitmap*)list_get_item(self->screen->child_list, i);
- MAKERECT(wnd_rect, b->left, b->top, b->width, b->height);
- if (rect_intersect(rect, &wnd_rect, 0))
+ if (rect->top < 0)
{
- return 0;
+ return 0;
+ }
+
+ if (rect->right >= self->screen->width)
+ {
+ return 0;
+ }
+
+ if (rect->bottom >= self->screen->height)
+ {
+ return 0;
}
+
+ i = list_index_of(self->screen->child_list, (long)wnd);
i--;
- }
- return 1;
+
+ while (i >= 0)
+ {
+ b = (struct xrdp_bitmap *)list_get_item(self->screen->child_list, i);
+ MAKERECT(wnd_rect, b->left, b->top, b->width, b->height);
+
+ if (rect_intersect(rect, &wnd_rect, 0))
+ {
+ return 0;
+ }
+
+ i--;
+ }
+
+ return 1;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_move_window(struct xrdp_wm* self, struct xrdp_bitmap* wnd,
+xrdp_wm_move_window(struct xrdp_wm *self, struct xrdp_bitmap *wnd,
int dx, int dy)
{
- struct xrdp_rect rect1;
- struct xrdp_rect rect2;
- struct xrdp_region* r;
- int i;
-
- MAKERECT(rect1, wnd->left, wnd->top, wnd->width, wnd->height);
- if (xrdp_wm_is_rect_vis(self, wnd, &rect1))
- {
- rect2 = rect1;
- RECTOFFSET(rect2, dx, dy);
- if (xrdp_wm_is_rect_vis(self, wnd, &rect2))
- { /* if both src and dst are unobscured, we can do a bitblt move */
- xrdp_wm_bitblt(self, self->screen, wnd->left + dx, wnd->top + dy,
- self->screen, wnd->left, wnd->top,
- wnd->width, wnd->height, 0xcc);
- wnd->left += dx;
- wnd->top += dy;
- r = xrdp_region_create(self);
- xrdp_region_add_rect(r, &rect1);
- xrdp_region_subtract_rect(r, &rect2);
- i = 0;
- while (xrdp_region_get_rect(r, i, &rect1) == 0)
- {
- xrdp_bitmap_invalidate(self->screen, &rect1);
- i++;
- }
- xrdp_region_delete(r);
- return 0;
- }
- }
- wnd->left += dx;
- wnd->top += dy;
- xrdp_bitmap_invalidate(self->screen, &rect1);
- xrdp_bitmap_invalidate(wnd, 0);
- return 0;
+ struct xrdp_rect rect1;
+ struct xrdp_rect rect2;
+ struct xrdp_region *r;
+ int i;
+
+ MAKERECT(rect1, wnd->left, wnd->top, wnd->width, wnd->height);
+
+ if (xrdp_wm_is_rect_vis(self, wnd, &rect1))
+ {
+ rect2 = rect1;
+ RECTOFFSET(rect2, dx, dy);
+
+ if (xrdp_wm_is_rect_vis(self, wnd, &rect2))
+ {
+ /* if both src and dst are unobscured, we can do a bitblt move */
+ xrdp_wm_bitblt(self, self->screen, wnd->left + dx, wnd->top + dy,
+ self->screen, wnd->left, wnd->top,
+ wnd->width, wnd->height, 0xcc);
+ wnd->left += dx;
+ wnd->top += dy;
+ r = xrdp_region_create(self);
+ xrdp_region_add_rect(r, &rect1);
+ xrdp_region_subtract_rect(r, &rect2);
+ i = 0;
+
+ while (xrdp_region_get_rect(r, i, &rect1) == 0)
+ {
+ xrdp_bitmap_invalidate(self->screen, &rect1);
+ i++;
+ }
+
+ xrdp_region_delete(r);
+ return 0;
+ }
+ }
+
+ wnd->left += dx;
+ wnd->top += dy;
+ xrdp_bitmap_invalidate(self->screen, &rect1);
+ xrdp_bitmap_invalidate(wnd, 0);
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_undraw_dragging_box(struct xrdp_wm* self, int do_begin_end)
+xrdp_wm_undraw_dragging_box(struct xrdp_wm *self, int do_begin_end)
{
- int boxx;
- int boxy;
+ int boxx;
+ int boxy;
- if (self == 0)
- {
- return 0;
- }
- if (self->dragging)
- {
- if (self->draggingxorstate)
+ if (self == 0)
{
- if (do_begin_end)
- {
- xrdp_painter_begin_update(self->painter);
- }
- boxx = self->draggingx - self->draggingdx;
- boxy = self->draggingy - self->draggingdy;
- xrdp_wm_xor_pat(self, boxx, boxy, self->draggingcx, self->draggingcy);
- self->draggingxorstate = 0;
- if (do_begin_end)
- {
- xrdp_painter_end_update(self->painter);
- }
+ return 0;
}
- }
- return 0;
+
+ if (self->dragging)
+ {
+ if (self->draggingxorstate)
+ {
+ if (do_begin_end)
+ {
+ xrdp_painter_begin_update(self->painter);
+ }
+
+ boxx = self->draggingx - self->draggingdx;
+ boxy = self->draggingy - self->draggingdy;
+ xrdp_wm_xor_pat(self, boxx, boxy, self->draggingcx, self->draggingcy);
+ self->draggingxorstate = 0;
+
+ if (do_begin_end)
+ {
+ xrdp_painter_end_update(self->painter);
+ }
+ }
+ }
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_draw_dragging_box(struct xrdp_wm* self, int do_begin_end)
+xrdp_wm_draw_dragging_box(struct xrdp_wm *self, int do_begin_end)
{
- int boxx;
- int boxy;
+ int boxx;
+ int boxy;
- if (self == 0)
- {
- return 0;
- }
- if (self->dragging)
- {
- if (!self->draggingxorstate)
+ if (self == 0)
{
- if (do_begin_end)
- {
- xrdp_painter_begin_update(self->painter);
- }
- boxx = self->draggingx - self->draggingdx;
- boxy = self->draggingy - self->draggingdy;
- xrdp_wm_xor_pat(self, boxx, boxy, self->draggingcx, self->draggingcy);
- self->draggingxorstate = 1;
- if (do_begin_end)
- {
- xrdp_painter_end_update(self->painter);
- }
+ return 0;
}
- }
- return 0;
+
+ if (self->dragging)
+ {
+ if (!self->draggingxorstate)
+ {
+ if (do_begin_end)
+ {
+ xrdp_painter_begin_update(self->painter);
+ }
+
+ boxx = self->draggingx - self->draggingdx;
+ boxy = self->draggingy - self->draggingdy;
+ xrdp_wm_xor_pat(self, boxx, boxy, self->draggingcx, self->draggingcy);
+ self->draggingxorstate = 1;
+
+ if (do_begin_end)
+ {
+ xrdp_painter_end_update(self->painter);
+ }
+ }
+ }
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_mouse_move(struct xrdp_wm* self, int x, int y)
+xrdp_wm_mouse_move(struct xrdp_wm *self, int x, int y)
{
- struct xrdp_bitmap* b;
+ struct xrdp_bitmap *b;
- if (self == 0)
- {
- return 0;
- }
- if (x < 0)
- {
- x = 0;
- }
- if (y < 0)
- {
- y = 0;
- }
- if (x >= self->screen->width)
- {
- x = self->screen->width;
- }
- if (y >= self->screen->height)
- {
- y = self->screen->height;
- }
- self->mouse_x = x;
- self->mouse_y = y;
- if (self->dragging)
- {
- xrdp_painter_begin_update(self->painter);
- xrdp_wm_undraw_dragging_box(self, 0);
- self->draggingx = x;
- self->draggingy = y;
- xrdp_wm_draw_dragging_box(self, 0);
- xrdp_painter_end_update(self->painter);
- return 0;
- }
- b = xrdp_wm_at_pos(self->screen, x, y, 0);
- if (b == 0) /* if b is null, the movment must be over the screen */
- {
- if (self->screen->pointer != self->current_pointer)
- {
- xrdp_wm_set_pointer(self, self->screen->pointer);
- self->current_pointer = self->screen->pointer;
- }
- if (self->mm->mod != 0) /* if screen is mod controled */
- {
- if (self->mm->mod->mod_event != 0)
- {
- self->mm->mod->mod_event(self->mm->mod, WM_MOUSEMOVE, x, y, 0, 0);
- }
- }
- }
- if (self->button_down != 0)
- {
- if (b == self->button_down && self->button_down->state == 0)
- {
- self->button_down->state = 1;
- xrdp_bitmap_invalidate(self->button_down, 0);
- }
- else if (b != self->button_down)
- {
- self->button_down->state = 0;
- xrdp_bitmap_invalidate(self->button_down, 0);
- }
- }
- if (b != 0)
- {
- if (!self->dragging)
- {
- if (b->pointer != self->current_pointer)
- {
- xrdp_wm_set_pointer(self, b->pointer);
- self->current_pointer = b->pointer;
- }
- xrdp_bitmap_def_proc(b, WM_MOUSEMOVE,
- xrdp_bitmap_from_screenx(b, x),
- xrdp_bitmap_from_screeny(b, y));
- if (self->button_down == 0)
- {
- if (b->notify != 0)
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (x < 0)
+ {
+ x = 0;
+ }
+
+ if (y < 0)
+ {
+ y = 0;
+ }
+
+ if (x >= self->screen->width)
+ {
+ x = self->screen->width;
+ }
+
+ if (y >= self->screen->height)
+ {
+ y = self->screen->height;
+ }
+
+ self->mouse_x = x;
+ self->mouse_y = y;
+
+ if (self->dragging)
+ {
+ xrdp_painter_begin_update(self->painter);
+ xrdp_wm_undraw_dragging_box(self, 0);
+ self->draggingx = x;
+ self->draggingy = y;
+ xrdp_wm_draw_dragging_box(self, 0);
+ xrdp_painter_end_update(self->painter);
+ return 0;
+ }
+
+ b = xrdp_wm_at_pos(self->screen, x, y, 0);
+
+ if (b == 0) /* if b is null, the movment must be over the screen */
+ {
+ if (self->screen->pointer != self->current_pointer)
+ {
+ xrdp_wm_set_pointer(self, self->screen->pointer);
+ self->current_pointer = self->screen->pointer;
+ }
+
+ if (self->mm->mod != 0) /* if screen is mod controled */
{
- b->notify(b->owner, b, 2, x, y);
+ if (self->mm->mod->mod_event != 0)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_MOUSEMOVE, x, y, 0, 0);
+ }
}
- }
}
- }
- return 0;
+
+ if (self->button_down != 0)
+ {
+ if (b == self->button_down && self->button_down->state == 0)
+ {
+ self->button_down->state = 1;
+ xrdp_bitmap_invalidate(self->button_down, 0);
+ }
+ else if (b != self->button_down)
+ {
+ self->button_down->state = 0;
+ xrdp_bitmap_invalidate(self->button_down, 0);
+ }
+ }
+
+ if (b != 0)
+ {
+ if (!self->dragging)
+ {
+ if (b->pointer != self->current_pointer)
+ {
+ xrdp_wm_set_pointer(self, b->pointer);
+ self->current_pointer = b->pointer;
+ }
+
+ xrdp_bitmap_def_proc(b, WM_MOUSEMOVE,
+ xrdp_bitmap_from_screenx(b, x),
+ xrdp_bitmap_from_screeny(b, y));
+
+ if (self->button_down == 0)
+ {
+ if (b->notify != 0)
+ {
+ b->notify(b->owner, b, 2, x, y);
+ }
+ }
+ }
+ }
+
+ return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_clear_popup(struct xrdp_wm* self)
+xrdp_wm_clear_popup(struct xrdp_wm *self)
{
- int i;
- struct xrdp_rect rect;
- //struct xrdp_bitmap* b;
-
- //b = 0;
- if (self->popup_wnd != 0)
- {
- //b = self->popup_wnd->popped_from;
- i = list_index_of(self->screen->child_list, (long)self->popup_wnd);
- list_remove_item(self->screen->child_list, i);
- MAKERECT(rect, self->popup_wnd->left, self->popup_wnd->top,
- self->popup_wnd->width, self->popup_wnd->height);
- xrdp_bitmap_invalidate(self->screen, &rect);
- xrdp_bitmap_delete(self->popup_wnd);
- }
- //xrdp_wm_set_focused(self, b->parent);
- return 0;
+ int i;
+ struct xrdp_rect rect;
+ //struct xrdp_bitmap* b;
+
+ //b = 0;
+ if (self->popup_wnd != 0)
+ {
+ //b = self->popup_wnd->popped_from;
+ i = list_index_of(self->screen->child_list, (long)self->popup_wnd);
+ list_remove_item(self->screen->child_list, i);
+ MAKERECT(rect, self->popup_wnd->left, self->popup_wnd->top,
+ self->popup_wnd->width, self->popup_wnd->height);
+ xrdp_bitmap_invalidate(self->screen, &rect);
+ xrdp_bitmap_delete(self->popup_wnd);
+ }
+
+ //xrdp_wm_set_focused(self, b->parent);
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_mouse_click(struct xrdp_wm* self, int x, int y, int but, int down)
+xrdp_wm_mouse_click(struct xrdp_wm *self, int x, int y, int but, int down)
{
- struct xrdp_bitmap* control;
- struct xrdp_bitmap* focus_out_control;
- struct xrdp_bitmap* wnd;
- int newx;
- int newy;
- int oldx;
- int oldy;
-
- if (self == 0)
- {
- return 0;
- }
- if (x < 0)
- {
- x = 0;
- }
- if (y < 0)
- {
- y = 0;
- }
- if (x >= self->screen->width)
- {
- x = self->screen->width;
- }
- if (y >= self->screen->height)
- {
- y = self->screen->height;
- }
- if (self->dragging && but == 1 && !down && self->dragging_window != 0)
- { /* if done dragging */
- self->draggingx = x;
- self->draggingy = y;
- newx = self->draggingx - self->draggingdx;
- newy = self->draggingy - self->draggingdy;
- oldx = self->dragging_window->left;
- oldy = self->dragging_window->top;
- /* draw xor box one more time */
- if (self->draggingxorstate)
- {
- xrdp_wm_xor_pat(self, newx, newy, self->draggingcx, self->draggingcy);
- }
- self->draggingxorstate = 0;
- /* move screen to new location */
- xrdp_wm_move_window(self, self->dragging_window, newx - oldx, newy - oldy);
- self->dragging_window = 0;
- self->dragging = 0;
- }
- wnd = 0;
- control = xrdp_wm_at_pos(self->screen, x, y, &wnd);
- if (control == 0)
- {
- if (self->mm->mod != 0) /* if screen is mod controled */
- {
- if (self->mm->mod->mod_event != 0)
- {
- if (but == 1 && down)
+ struct xrdp_bitmap *control;
+ struct xrdp_bitmap *focus_out_control;
+ struct xrdp_bitmap *wnd;
+ int newx;
+ int newy;
+ int oldx;
+ int oldy;
+
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (x < 0)
+ {
+ x = 0;
+ }
+
+ if (y < 0)
+ {
+ y = 0;
+ }
+
+ if (x >= self->screen->width)
+ {
+ x = self->screen->width;
+ }
+
+ if (y >= self->screen->height)
+ {
+ y = self->screen->height;
+ }
+
+ if (self->dragging && but == 1 && !down && self->dragging_window != 0)
+ {
+ /* if done dragging */
+ self->draggingx = x;
+ self->draggingy = y;
+ newx = self->draggingx - self->draggingdx;
+ newy = self->draggingy - self->draggingdy;
+ oldx = self->dragging_window->left;
+ oldy = self->dragging_window->top;
+
+ /* draw xor box one more time */
+ if (self->draggingxorstate)
{
- self->mm->mod->mod_event(self->mm->mod, WM_LBUTTONDOWN, x, y, 0, 0);
+ xrdp_wm_xor_pat(self, newx, newy, self->draggingcx, self->draggingcy);
}
- else if (but == 1 && !down)
+
+ self->draggingxorstate = 0;
+ /* move screen to new location */
+ xrdp_wm_move_window(self, self->dragging_window, newx - oldx, newy - oldy);
+ self->dragging_window = 0;
+ self->dragging = 0;
+ }
+
+ wnd = 0;
+ control = xrdp_wm_at_pos(self->screen, x, y, &wnd);
+
+ if (control == 0)
+ {
+ if (self->mm->mod != 0) /* if screen is mod controled */
{
- self->mm->mod->mod_event(self->mm->mod, WM_LBUTTONUP, x, y, 0, 0);
+ if (self->mm->mod->mod_event != 0)
+ {
+ if (but == 1 && down)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_LBUTTONDOWN, x, y, 0, 0);
+ }
+ else if (but == 1 && !down)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_LBUTTONUP, x, y, 0, 0);
+ }
+
+ if (but == 2 && down)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_RBUTTONDOWN, x, y, 0, 0);
+ }
+ else if (but == 2 && !down)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_RBUTTONUP, x, y, 0, 0);
+ }
+
+ if (but == 3 && down)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_BUTTON3DOWN, x, y, 0, 0);
+ }
+ else if (but == 3 && !down)
+ {
+ self->mm->mod->mod_event(self->mm->mod, WM_BUTTON3UP, x, y, 0, 0);
+ }
+
+ if (but == 4)
+ {
+ 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->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);
+ }
+ }
}
- if (but == 2 && down)
+ }
+
+ if (self->popup_wnd != 0)
+ {
+ if (self->popup_wnd == control && !down)
{
- self->mm->mod->mod_event(self->mm->mod, WM_RBUTTONDOWN, x, y, 0, 0);
+ xrdp_bitmap_def_proc(self->popup_wnd, WM_LBUTTONUP, x, y);
+ xrdp_wm_clear_popup(self);
+ self->button_down = 0;
+ return 0;
}
- else if (but == 2 && !down)
+ else if (self->popup_wnd != control && down)
{
- self->mm->mod->mod_event(self->mm->mod, WM_RBUTTONUP, x, y, 0, 0);
+ xrdp_wm_clear_popup(self);
+ self->button_down = 0;
+ return 0;
}
- if (but == 3 && down)
+ }
+
+ if (control != 0)
+ {
+ if (wnd != 0)
{
- self->mm->mod->mod_event(self->mm->mod, WM_BUTTON3DOWN, x, y, 0, 0);
+ if (wnd->modal_dialog != 0) /* if window has a modal dialog */
+ {
+ return 0;
+ }
+
+ if (control == wnd)
+ {
+ }
+ else if (control->tab_stop)
+ {
+ focus_out_control = wnd->focused_control;
+ wnd->focused_control = control;
+ xrdp_bitmap_invalidate(focus_out_control, 0);
+ xrdp_bitmap_invalidate(control, 0);
+ }
}
- else if (but == 3 && !down)
+
+ if ((control->type == WND_TYPE_BUTTON ||
+ control->type == WND_TYPE_COMBO) &&
+ but == 1 && !down && self->button_down == control)
{
- self->mm->mod->mod_event(self->mm->mod, WM_BUTTON3UP, x, y, 0, 0);
+ /* if clicking up on a button that was clicked down */
+ self->button_down = 0;
+ control->state = 0;
+ xrdp_bitmap_invalidate(control, 0);
+
+ if (control->parent != 0)
+ {
+ if (control->parent->notify != 0)
+ {
+ /* control can be invalid after this */
+ control->parent->notify(control->owner, control, 1, x, y);
+ }
+ }
}
- if (but == 4)
+ else if ((control->type == WND_TYPE_BUTTON ||
+ control->type == WND_TYPE_COMBO) &&
+ but == 1 && down)
{
- 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 clicking down on a button or combo */
+ self->button_down = control;
+ control->state = 1;
+ xrdp_bitmap_invalidate(control, 0);
+
+ if (control->type == WND_TYPE_COMBO)
+ {
+ xrdp_wm_pu(self, control);
+ }
}
- if (but == 5)
+ else if (but == 1 && down)
{
- 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);
+ if (self->popup_wnd == 0)
+ {
+ xrdp_wm_set_focused(self, wnd);
+
+ if (control->type == WND_TYPE_WND && y < (control->top + 21))
+ {
+ /* if dragging */
+ if (self->dragging) /* rarely happens */
+ {
+ newx = self->draggingx - self->draggingdx;
+ newy = self->draggingy - self->draggingdy;
+
+ if (self->draggingxorstate)
+ {
+ xrdp_wm_xor_pat(self, newx, newy,
+ self->draggingcx, self->draggingcy);
+ }
+
+ self->draggingxorstate = 0;
+ }
+
+ self->dragging = 1;
+ self->dragging_window = control;
+ self->draggingorgx = control->left;
+ self->draggingorgy = control->top;
+ self->draggingx = x;
+ self->draggingy = y;
+ self->draggingdx = x - control->left;
+ self->draggingdy = y - control->top;
+ self->draggingcx = control->width;
+ self->draggingcy = control->height;
+ }
+ }
}
- }
}
- }
- if (self->popup_wnd != 0)
- {
- if (self->popup_wnd == control && !down)
+ else
{
- xrdp_bitmap_def_proc(self->popup_wnd, WM_LBUTTONUP, x, y);
- xrdp_wm_clear_popup(self);
- self->button_down = 0;
- return 0;
+ xrdp_wm_set_focused(self, 0);
}
- else if (self->popup_wnd != control && down)
+
+ /* no matter what, mouse is up, reset button_down */
+ if (but == 1 && !down && self->button_down != 0)
{
- xrdp_wm_clear_popup(self);
- self->button_down = 0;
- return 0;
+ self->button_down = 0;
}
- }
- if (control != 0)
- {
- if (wnd != 0)
+
+ return 0;
+}
+
+/*****************************************************************************/
+int APP_CC
+xrdp_wm_key(struct xrdp_wm *self, int device_flags, int scan_code)
+{
+ int msg;
+ struct xrdp_key_info *ki;
+
+ /*g_printf("count %d\n", self->key_down_list->count);*/
+ scan_code = scan_code % 128;
+
+ if (self->popup_wnd != 0)
{
- if (wnd->modal_dialog != 0) /* if window has a modal dialog */
- {
+ xrdp_wm_clear_popup(self);
return 0;
- }
- if (control == wnd)
- {
- }
- else if (control->tab_stop)
- {
- focus_out_control = wnd->focused_control;
- wnd->focused_control = control;
- xrdp_bitmap_invalidate(focus_out_control, 0);
- xrdp_bitmap_invalidate(control, 0);
- }
- }
- if ((control->type == WND_TYPE_BUTTON ||
- control->type == WND_TYPE_COMBO) &&
- but == 1 && !down && self->button_down == control)
- { /* if clicking up on a button that was clicked down */
- self->button_down = 0;
- control->state = 0;
- xrdp_bitmap_invalidate(control, 0);
- if (control->parent != 0)
- {
- if (control->parent->notify != 0)
+ }
+
+ if (device_flags & KBD_FLAG_UP) /* 0x8000 */
+ {
+ self->keys[scan_code] = 0;
+ msg = WM_KEYUP;
+ }
+ else /* key down */
+ {
+ self->keys[scan_code] = 1 | device_flags;
+ msg = WM_KEYDOWN;
+
+ switch (scan_code)
{
- /* control can be invalid after this */
- control->parent->notify(control->owner, control, 1, x, y);
+ case 58:
+ self->caps_lock = !self->caps_lock;
+ break; /* caps lock */
+ case 69:
+ self->num_lock = !self->num_lock;
+ break; /* num lock */
+ case 70:
+ self->scroll_lock = !self->scroll_lock;
+ break; /* scroll lock */
}
- }
- }
- else if ((control->type == WND_TYPE_BUTTON ||
- control->type == WND_TYPE_COMBO) &&
- but == 1 && down)
- { /* if clicking down on a button or combo */
- self->button_down = control;
- control->state = 1;
- xrdp_bitmap_invalidate(control, 0);
- if (control->type == WND_TYPE_COMBO)
- {
- xrdp_wm_pu(self, control);
- }
- }
- else if (but == 1 && down)
- {
- if (self->popup_wnd == 0)
- {
- xrdp_wm_set_focused(self, wnd);
- if (control->type == WND_TYPE_WND && y < (control->top + 21))
- { /* if dragging */
- if (self->dragging) /* rarely happens */
- {
- newx = self->draggingx - self->draggingdx;
- newy = self->draggingy - self->draggingdy;
- if (self->draggingxorstate)
+ }
+
+ if (self->mm->mod != 0)
+ {
+ if (self->mm->mod->mod_event != 0)
+ {
+ ki = get_key_info_from_scan_code
+ (device_flags, scan_code, self->keys, self->caps_lock,
+ self->num_lock, self->scroll_lock,
+ &(self->keymap));
+
+ if (ki != 0)
{
- xrdp_wm_xor_pat(self, newx, newy,
- self->draggingcx, self->draggingcy);
+ self->mm->mod->mod_event(self->mm->mod, msg, ki->chr, ki->sym,
+ scan_code, device_flags);
}
- self->draggingxorstate = 0;
- }
- self->dragging = 1;
- self->dragging_window = control;
- self->draggingorgx = control->left;
- self->draggingorgy = control->top;
- self->draggingx = x;
- self->draggingy = y;
- self->draggingdx = x - control->left;
- self->draggingdy = y - control->top;
- self->draggingcx = control->width;
- self->draggingcy = control->height;
}
- }
- }
- }
- else
- {
- xrdp_wm_set_focused(self, 0);
- }
- /* no matter what, mouse is up, reset button_down */
- if (but == 1 && !down && self->button_down != 0)
- {
- self->button_down = 0;
- }
- return 0;
-}
+ }
+ else if (self->focused_window != 0)
+ {
+ xrdp_bitmap_def_proc(self->focused_window,
+ msg, scan_code, device_flags);
+ }
-/*****************************************************************************/
-int APP_CC
-xrdp_wm_key(struct xrdp_wm* self, int device_flags, int scan_code)
-{
- int msg;
- struct xrdp_key_info* ki;
-
- /*g_printf("count %d\n", self->key_down_list->count);*/
- scan_code = scan_code % 128;
- if (self->popup_wnd != 0)
- {
- xrdp_wm_clear_popup(self);
return 0;
- }
- if (device_flags & KBD_FLAG_UP) /* 0x8000 */
- {
- self->keys[scan_code] = 0;
- msg = WM_KEYUP;
- }
- else /* key down */
- {
- self->keys[scan_code] = 1 | device_flags;
- msg = WM_KEYDOWN;
- switch (scan_code)
- {
- case 58:
- self->caps_lock = !self->caps_lock;
- break; /* caps lock */
- case 69:
- self->num_lock = !self->num_lock;
- break; /* num lock */
- case 70:
- self->scroll_lock = !self->scroll_lock;
- break; /* scroll lock */
- }
- }
- if (self->mm->mod != 0)
- {
- if (self->mm->mod->mod_event != 0)
- {
- ki = get_key_info_from_scan_code
- (device_flags, scan_code, self->keys, self->caps_lock,
- self->num_lock, self->scroll_lock,
- &(self->keymap));
- if (ki != 0)
- {
- self->mm->mod->mod_event(self->mm->mod, msg, ki->chr, ki->sym,
- scan_code, device_flags);
- }
- }
- }
- else if (self->focused_window != 0)
- {
- xrdp_bitmap_def_proc(self->focused_window,
- msg, scan_code, device_flags);
- }
- return 0;
}
/*****************************************************************************/
/* happens when client gets focus and sends key modifier info */
int APP_CC
-xrdp_wm_key_sync(struct xrdp_wm* self, int device_flags, int key_flags)
+xrdp_wm_key_sync(struct xrdp_wm *self, int device_flags, int key_flags)
{
- self->num_lock = 0;
- self->scroll_lock = 0;
- self->caps_lock = 0;
- if (key_flags & 1)
- {
- self->scroll_lock = 1;
- }
- if (key_flags & 2)
- {
- self->num_lock = 1;
- }
- if (key_flags & 4)
- {
- self->caps_lock = 1;
- }
- if (self->mm->mod != 0)
- {
- if (self->mm->mod->mod_event != 0)
- {
- self->mm->mod->mod_event(self->mm->mod, 17, key_flags, device_flags,
- key_flags, device_flags);
- }
- }
- return 0;
+ self->num_lock = 0;
+ self->scroll_lock = 0;
+ self->caps_lock = 0;
+
+ if (key_flags & 1)
+ {
+ self->scroll_lock = 1;
+ }
+
+ if (key_flags & 2)
+ {
+ self->num_lock = 1;
+ }
+
+ if (key_flags & 4)
+ {
+ self->caps_lock = 1;
+ }
+
+ if (self->mm->mod != 0)
+ {
+ if (self->mm->mod->mod_event != 0)
+ {
+ self->mm->mod->mod_event(self->mm->mod, 17, key_flags, device_flags,
+ key_flags, device_flags);
+ }
+ }
+
+ return 0;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_pu(struct xrdp_wm* self, struct xrdp_bitmap* control)
+xrdp_wm_pu(struct xrdp_wm *self, struct xrdp_bitmap *control)
{
- int x;
- int y;
+ int x;
+ int y;
- if (self == 0)
- {
- return 0;
- }
- if (control == 0)
- {
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ if (control == 0)
+ {
+ return 0;
+ }
+
+ self->popup_wnd = xrdp_bitmap_create(control->width, DEFAULT_WND_SPECIAL_H,
+ self->screen->bpp,
+ WND_TYPE_SPECIAL, self);
+ self->popup_wnd->popped_from = control;
+ self->popup_wnd->parent = self->screen;
+ self->popup_wnd->owner = self->screen;
+ x = xrdp_bitmap_to_screenx(control, 0);
+ y = xrdp_bitmap_to_screeny(control, 0);
+ self->popup_wnd->left = x;
+ self->popup_wnd->top = y + control->height;
+ self->popup_wnd->item_index = control->item_index;
+ list_insert_item(self->screen->child_list, 0, (long)self->popup_wnd);
+ xrdp_bitmap_invalidate(self->popup_wnd, 0);
return 0;
- }
- self->popup_wnd = xrdp_bitmap_create(control->width, DEFAULT_WND_SPECIAL_H,
- self->screen->bpp,
- WND_TYPE_SPECIAL, self);
- self->popup_wnd->popped_from = control;
- self->popup_wnd->parent = self->screen;
- self->popup_wnd->owner = self->screen;
- x = xrdp_bitmap_to_screenx(control, 0);
- y = xrdp_bitmap_to_screeny(control, 0);
- self->popup_wnd->left = x;
- self->popup_wnd->top = y + control->height;
- self->popup_wnd->item_index = control->item_index;
- list_insert_item(self->screen->child_list, 0, (long)self->popup_wnd);
- xrdp_bitmap_invalidate(self->popup_wnd, 0);
- return 0;
}
/*****************************************************************************/
static int APP_CC
-xrdp_wm_process_input_mouse(struct xrdp_wm* self, int device_flags,
+xrdp_wm_process_input_mouse(struct xrdp_wm *self, int device_flags,
int x, int y)
{
- DEBUG(("mouse event flags %4.4x x %d y %d", device_flags, x, y));
- if (device_flags & MOUSE_FLAG_MOVE) /* 0x0800 */
- {
- xrdp_wm_mouse_move(self, x, y);
- }
- if (device_flags & MOUSE_FLAG_BUTTON1) /* 0x1000 */
- {
- if (device_flags & MOUSE_FLAG_DOWN) /* 0x8000 */
+ DEBUG(("mouse event flags %4.4x x %d y %d", device_flags, x, y));
+
+ if (device_flags & MOUSE_FLAG_MOVE) /* 0x0800 */
{
- xrdp_wm_mouse_click(self, x, y, 1, 1);
+ xrdp_wm_mouse_move(self, x, y);
}
- else
+
+ if (device_flags & MOUSE_FLAG_BUTTON1) /* 0x1000 */
{
- xrdp_wm_mouse_click(self, x, y, 1, 0);
+ if (device_flags & MOUSE_FLAG_DOWN) /* 0x8000 */
+ {
+ xrdp_wm_mouse_click(self, x, y, 1, 1);
+ }
+ else
+ {
+ xrdp_wm_mouse_click(self, x, y, 1, 0);
+ }
}
- }
- if (device_flags & MOUSE_FLAG_BUTTON2) /* 0x2000 */
- {
- if (device_flags & MOUSE_FLAG_DOWN) /* 0x8000 */
+
+ if (device_flags & MOUSE_FLAG_BUTTON2) /* 0x2000 */
{
- xrdp_wm_mouse_click(self, x, y, 2, 1);
+ if (device_flags & MOUSE_FLAG_DOWN) /* 0x8000 */
+ {
+ xrdp_wm_mouse_click(self, x, y, 2, 1);
+ }
+ else
+ {
+ xrdp_wm_mouse_click(self, x, y, 2, 0);
+ }
}
- else
+
+ if (device_flags & MOUSE_FLAG_BUTTON3) /* 0x4000 */
{
- xrdp_wm_mouse_click(self, x, y, 2, 0);
+ if (device_flags & MOUSE_FLAG_DOWN) /* 0x8000 */
+ {
+ xrdp_wm_mouse_click(self, x, y, 3, 1);
+ }
+ else
+ {
+ xrdp_wm_mouse_click(self, x, y, 3, 0);
+ }
}
- }
- if (device_flags & MOUSE_FLAG_BUTTON3) /* 0x4000 */
- {
- if (device_flags & MOUSE_FLAG_DOWN) /* 0x8000 */
+
+ if (device_flags == MOUSE_FLAG_BUTTON4 || /* 0x0280 */
+ device_flags == 0x0278)
{
- xrdp_wm_mouse_click(self, x, y, 3, 1);
+ xrdp_wm_mouse_click(self, 0, 0, 4, 0);
}
- else
+
+ if (device_flags == MOUSE_FLAG_BUTTON5 || /* 0x0380 */
+ device_flags == 0x0388)
{
- xrdp_wm_mouse_click(self, x, y, 3, 0);
- }
- }
- if (device_flags == MOUSE_FLAG_BUTTON4 || /* 0x0280 */
- device_flags == 0x0278)
- {
- xrdp_wm_mouse_click(self, 0, 0, 4, 0);
- }
- if (device_flags == MOUSE_FLAG_BUTTON5 || /* 0x0380 */
- device_flags == 0x0388)
- {
- xrdp_wm_mouse_click(self, 0, 0, 5, 0);
- }
- return 0;
+ xrdp_wm_mouse_click(self, 0, 0, 5, 0);
+ }
+
+ return 0;
}
/******************************************************************************/
@@ -1386,34 +1531,37 @@ xrdp_wm_process_input_mouse(struct xrdp_wm* self, int device_flags,
param3 = pointer to data
param4 = total size */
static int APP_CC
-xrdp_wm_process_channel_data(struct xrdp_wm* self,
- tbus param1, tbus param2,
- tbus param3, tbus param4)
+xrdp_wm_process_channel_data(struct xrdp_wm *self,
+ tbus param1, tbus param2,
+ tbus param3, tbus param4)
{
- int rv;
- int chanid ;
- rv = 1;
- if (self->mm->mod != 0)
- {
- chanid = LOWORD(param1);
- if(is_channel_allowed(self, chanid))
- {
- if (self->mm->usechansrv)
- {
- rv = xrdp_mm_process_channel_data(self->mm, param1, param2,
- param3, param4);
- }
- else
- {
- if (self->mm->mod->mod_event != 0)
+ int rv;
+ int chanid ;
+ rv = 1;
+
+ if (self->mm->mod != 0)
+ {
+ chanid = LOWORD(param1);
+
+ if (is_channel_allowed(self, chanid))
{
- rv = self->mm->mod->mod_event(self->mm->mod, 0x5555, param1, param2,
- param3, param4);
+ if (self->mm->usechansrv)
+ {
+ rv = xrdp_mm_process_channel_data(self->mm, param1, param2,
+ param3, param4);
+ }
+ else
+ {
+ if (self->mm->mod->mod_event != 0)
+ {
+ rv = self->mm->mod->mod_event(self->mm->mod, 0x5555, param1, param2,
+ param3, param4);
+ }
+ }
}
- }
}
- }
- return rv;
+
+ return rv;
}
/******************************************************************************/
@@ -1421,266 +1569,295 @@ xrdp_wm_process_channel_data(struct xrdp_wm* self,
int DEFAULT_CC
callback(long id, int msg, long param1, long param2, long param3, long param4)
{
- int rv;
- struct xrdp_wm* wm;
- struct xrdp_rect rect;
+ int rv;
+ struct xrdp_wm *wm;
+ struct xrdp_rect rect;
- if (id == 0) /* "id" should be "struct xrdp_process*" as long */
- {
- return 0;
- }
- wm = ((struct xrdp_process*)id)->wm;
- if (wm == 0)
- {
- return 0;
- }
- rv = 0;
- switch (msg)
- {
- case 0: /* RDP_INPUT_SYNCHRONIZE */
- rv = xrdp_wm_key_sync(wm, param3, param1);
- break;
- case 4: /* RDP_INPUT_SCANCODE */
- rv = xrdp_wm_key(wm, param3, param1);
- break;
- case 0x8001: /* RDP_INPUT_MOUSE */
- rv = xrdp_wm_process_input_mouse(wm, param3, param1, param2);
- break;
- case 0x4444: /* invalidate, this is not from RDP_DATA_PDU_INPUT */
- /* like the rest, its from RDP_PDU_DATA with code 33 */
- /* its the rdp client asking for a screen update */
- MAKERECT(rect, param1, param2, param3, param4);
- rv = xrdp_bitmap_invalidate(wm->screen, &rect);
- break;
- case 0x5555: /* called from xrdp_channel.c, channel data has come in,
+ if (id == 0) /* "id" should be "struct xrdp_process*" as long */
+ {
+ return 0;
+ }
+
+ wm = ((struct xrdp_process *)id)->wm;
+
+ if (wm == 0)
+ {
+ return 0;
+ }
+
+ rv = 0;
+
+ switch (msg)
+ {
+ case 0: /* RDP_INPUT_SYNCHRONIZE */
+ rv = xrdp_wm_key_sync(wm, param3, param1);
+ break;
+ case 4: /* RDP_INPUT_SCANCODE */
+ rv = xrdp_wm_key(wm, param3, param1);
+ break;
+ case 0x8001: /* RDP_INPUT_MOUSE */
+ rv = xrdp_wm_process_input_mouse(wm, param3, param1, param2);
+ break;
+ case 0x4444: /* invalidate, this is not from RDP_DATA_PDU_INPUT */
+ /* like the rest, its from RDP_PDU_DATA with code 33 */
+ /* its the rdp client asking for a screen update */
+ MAKERECT(rect, param1, param2, param3, param4);
+ rv = xrdp_bitmap_invalidate(wm->screen, &rect);
+ break;
+ case 0x5555: /* called from xrdp_channel.c, channel data has come in,
pass it to module if there is one */
- rv = xrdp_wm_process_channel_data(wm, param1, param2, param3, param4);
- break;
- }
- return rv;
+ rv = xrdp_wm_process_channel_data(wm, param1, param2, param3, param4);
+ break;
+ }
+
+ return rv;
}
/******************************************************************************/
/* returns error */
/* this gets called when there is nothing on any socket */
static int APP_CC
-xrdp_wm_login_mode_changed(struct xrdp_wm* self)
+xrdp_wm_login_mode_changed(struct xrdp_wm *self)
{
- if (self == 0)
- {
- return 0;
- }
- if (self->login_mode == 0)
- {
- /* this is the inital state of the login window */
- xrdp_wm_set_login_mode(self, 1); /* put the wm in login mode */
- list_clear(self->log);
- xrdp_wm_delete_all_childs(self);
- self->dragging = 0;
- xrdp_wm_init(self);
- }
- else if (self->login_mode == 2)
- {
- if (xrdp_mm_connect(self->mm) == 0)
- {
- xrdp_wm_set_login_mode(self, 3); /* put the wm in connected mode */
- xrdp_wm_delete_all_childs(self);
- self->dragging = 0;
+ if (self == 0)
+ {
+ return 0;
}
- else
+
+ if (self->login_mode == 0)
{
- /* we do nothing on connect error so far */
+ /* this is the inital state of the login window */
+ xrdp_wm_set_login_mode(self, 1); /* put the wm in login mode */
+ list_clear(self->log);
+ xrdp_wm_delete_all_childs(self);
+ self->dragging = 0;
+ xrdp_wm_init(self);
}
- }
- else if (self->login_mode == 10)
- {
- xrdp_wm_delete_all_childs(self);
- self->dragging = 0;
- xrdp_wm_set_login_mode(self, 11);
- }
- return 0;
+ else if (self->login_mode == 2)
+ {
+ if (xrdp_mm_connect(self->mm) == 0)
+ {
+ xrdp_wm_set_login_mode(self, 3); /* put the wm in connected mode */
+ xrdp_wm_delete_all_childs(self);
+ self->dragging = 0;
+ }
+ else
+ {
+ /* we do nothing on connect error so far */
+ }
+ }
+ else if (self->login_mode == 10)
+ {
+ xrdp_wm_delete_all_childs(self);
+ self->dragging = 0;
+ xrdp_wm_set_login_mode(self, 11);
+ }
+
+ 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,
+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)
- {
+ 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, reset the session when ok is clicked */
+ if (wm->mm->mod_handle == 0)
+ {
+ /* make sure autologin is off */
+ wm->session->client_info->rdp_autologin = 0;
+ xrdp_wm_set_login_mode(wm, 0); /* reset session */
+ }
+ }
+ }
+ else if (msg == WM_PAINT) /* 3 */
+ {
+ painter = (struct xrdp_painter *)param1;
+
+ if (painter != 0)
+ {
+ painter->fg_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;
- }
- 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, reset the session when ok is clicked */
- if (wm->mm->mod_handle == 0)
- {
- /* make sure autologin is off */
- wm->session->client_info->rdp_autologin = 0;
- xrdp_wm_set_login_mode(wm, 0); /* reset session */
- }
- }
- }
- else if (msg == WM_PAINT) /* 3 */
- {
- painter = (struct xrdp_painter*)param1;
- if (painter != 0)
- {
- painter->fg_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;
}
- void add_string_to_logwindow(char *msg,struct list* log)
- {
-
- char *new_part_message;
- char *current_pointer = msg ;
- int processedlen = 0;
- do{
- new_part_message = g_strndup(current_pointer,LOG_WINDOW_CHAR_PER_LINE) ;
- g_writeln(new_part_message);
- list_add_item(log, (long)new_part_message);
- processedlen = processedlen + g_strlen(new_part_message);
- current_pointer = current_pointer + g_strlen(new_part_message) ;
- }while((processedlen<g_strlen(msg)) && (processedlen<DEFAULT_STRING_LEN));
- }
+void add_string_to_logwindow(char *msg, struct list *log)
+{
+
+ char *new_part_message;
+ char *current_pointer = msg ;
+ int processedlen = 0;
+
+ do
+ {
+ new_part_message = g_strndup(current_pointer, LOG_WINDOW_CHAR_PER_LINE) ;
+ g_writeln(new_part_message);
+ list_add_item(log, (long)new_part_message);
+ processedlen = processedlen + g_strlen(new_part_message);
+ current_pointer = current_pointer + g_strlen(new_part_message) ;
+ }
+ while ((processedlen < g_strlen(msg)) && (processedlen < DEFAULT_STRING_LEN));
+}
/*****************************************************************************/
int APP_CC
-xrdp_wm_log_msg(struct xrdp_wm* self, char* msg)
+xrdp_wm_log_msg(struct xrdp_wm *self, char *msg)
{
- struct xrdp_bitmap* but;
- int w;
- int h;
- int xoffset;
- int yoffset;
-
- if (self->hide_log_window)
- {
+ struct xrdp_bitmap *but;
+ int w;
+ int h;
+ int xoffset;
+ int yoffset;
+
+ if (self->hide_log_window)
+ {
+ return 0;
+ }
+
+ add_string_to_logwindow(msg, self->log);
+
+ if (self->log_wnd == 0)
+ {
+ w = DEFAULT_WND_LOG_W;
+ h = DEFAULT_WND_LOG_H;
+ xoffset = 10;
+ yoffset = 10;
+
+ if (self->screen->width < w)
+ {
+ w = self->screen->width - 4;
+ xoffset = 2;
+ }
+
+ if (self->screen->height < h)
+ {
+ h = self->screen->height - 4;
+ yoffset = 2;
+ }
+
+ /* log window */
+ self->log_wnd = xrdp_bitmap_create(w, h, 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 = xoffset;
+ self->log_wnd->top = yoffset;
+ set_string(&(self->log_wnd->caption1), "Connection Log");
+ /* ok button */
+ but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, 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 = (w - DEFAULT_BUTTON_W) - xoffset;
+ but->top = (h - DEFAULT_BUTTON_H) - yoffset;
+ 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;
- }
- add_string_to_logwindow(msg,self->log);
- if (self->log_wnd == 0)
- {
- w = DEFAULT_WND_LOG_W;
- h = DEFAULT_WND_LOG_H;
- xoffset = 10;
- yoffset = 10;
- if (self->screen->width < w)
- {
- w = self->screen->width - 4;
- xoffset = 2;
- }
- if (self->screen->height < h)
- {
- h = self->screen->height - 4;
- yoffset = 2;
- }
- /* log window */
- self->log_wnd = xrdp_bitmap_create(w, h, 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 = xoffset;
- self->log_wnd->top = yoffset;
- set_string(&(self->log_wnd->caption1), "Connection Log");
- /* ok button */
- but = xrdp_bitmap_create(DEFAULT_BUTTON_W, DEFAULT_BUTTON_H, 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 = (w - DEFAULT_BUTTON_W) - xoffset;
- but->top = (h - DEFAULT_BUTTON_H) - yoffset;
- 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;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_get_wait_objs(struct xrdp_wm* self, tbus* robjs, int* rc,
- tbus* wobjs, int* wc, int* timeout)
+xrdp_wm_get_wait_objs(struct xrdp_wm *self, tbus *robjs, int *rc,
+ tbus *wobjs, int *wc, int *timeout)
{
- int i;
+ int i;
- if (self == 0)
- {
- return 0;
- }
- i = *rc;
- robjs[i++] = self->login_mode_event;
- *rc = i;
- return xrdp_mm_get_wait_objs(self->mm, robjs, rc, wobjs, wc, timeout);
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ i = *rc;
+ robjs[i++] = self->login_mode_event;
+ *rc = i;
+ return xrdp_mm_get_wait_objs(self->mm, robjs, rc, wobjs, wc, timeout);
}
/******************************************************************************/
int APP_CC
-xrdp_wm_check_wait_objs(struct xrdp_wm* self)
+xrdp_wm_check_wait_objs(struct xrdp_wm *self)
{
- int rv;
+ int rv;
- if (self == 0)
- {
- return 0;
- }
- rv = 0;
- if (g_is_wait_obj_set(self->login_mode_event))
- {
- g_reset_wait_obj(self->login_mode_event);
- xrdp_wm_login_mode_changed(self);
- }
- if (rv == 0)
- {
- rv = xrdp_mm_check_wait_objs(self->mm);
- }
- return rv;
+ if (self == 0)
+ {
+ return 0;
+ }
+
+ rv = 0;
+
+ if (g_is_wait_obj_set(self->login_mode_event))
+ {
+ g_reset_wait_obj(self->login_mode_event);
+ xrdp_wm_login_mode_changed(self);
+ }
+
+ if (rv == 0)
+ {
+ rv = xrdp_mm_check_wait_objs(self->mm);
+ }
+
+ return rv;
}
/*****************************************************************************/
int APP_CC
-xrdp_wm_set_login_mode(struct xrdp_wm* self, int login_mode)
+xrdp_wm_set_login_mode(struct xrdp_wm *self, int login_mode)
{
- self->login_mode = login_mode;
- g_set_wait_obj(self->login_mode_event);
- return 0;
+ self->login_mode = login_mode;
+ g_set_wait_obj(self->login_mode_event);
+ return 0;
}
diff --git a/xrdp/xrdpwin.c b/xrdp/xrdpwin.c
index 849f7112..ed6fa4c5 100644
--- a/xrdp/xrdpwin.c
+++ b/xrdp/xrdpwin.c
@@ -1,31 +1,29 @@
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- xrdp: A Remote Desktop Protocol server.
- Copyright (C) Jay Sorg 2004-2012
-
- main program
-
-*/
+/**
+ * xrdp: A Remote Desktop Protocol server.
+ *
+ * Copyright (C) Jay Sorg 2004-2012
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * main program
+ */
#if defined(_WIN32)
#include <windows.h>
#endif
#include "xrdp.h"
-static struct xrdp_listen* g_listen = 0;
+static struct xrdp_listen *g_listen = 0;
static long g_threadid = 0; /* main threadid */
#if defined(_WIN32)
@@ -48,113 +46,120 @@ long APP_CC
g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,
long sync_param2)
{
- long sync_result;
- int sync_command;
-
- if (tc_threadid_equal(tc_get_threadid(), g_threadid))
- {
- /* this is the main thread, call the function directly */
- sync_result = sync_func(sync_param1, sync_param2);
- }
- else
- {
- tc_mutex_lock(g_sync1_mutex);
- tc_mutex_lock(g_sync_mutex);
- g_sync_param1 = sync_param1;
- g_sync_param2 = sync_param2;
- g_sync_func = sync_func;
- g_sync_command = 100;
- tc_mutex_unlock(g_sync_mutex);
- g_set_wait_obj(g_sync_event);
- do
+ long sync_result;
+ int sync_command;
+
+ if (tc_threadid_equal(tc_get_threadid(), g_threadid))
{
- g_sleep(100);
- tc_mutex_lock(g_sync_mutex);
- sync_command = g_sync_command;
- sync_result = g_sync_result;
- tc_mutex_unlock(g_sync_mutex);
+ /* this is the main thread, call the function directly */
+ sync_result = sync_func(sync_param1, sync_param2);
}
- while (sync_command != 0);
- tc_mutex_unlock(g_sync1_mutex);
- }
- return sync_result;
+ else
+ {
+ tc_mutex_lock(g_sync1_mutex);
+ tc_mutex_lock(g_sync_mutex);
+ g_sync_param1 = sync_param1;
+ g_sync_param2 = sync_param2;
+ g_sync_func = sync_func;
+ g_sync_command = 100;
+ tc_mutex_unlock(g_sync_mutex);
+ g_set_wait_obj(g_sync_event);
+
+ do
+ {
+ g_sleep(100);
+ tc_mutex_lock(g_sync_mutex);
+ sync_command = g_sync_command;
+ sync_result = g_sync_result;
+ tc_mutex_unlock(g_sync_mutex);
+ }
+ while (sync_command != 0);
+
+ tc_mutex_unlock(g_sync1_mutex);
+ }
+
+ return sync_result;
}
/*****************************************************************************/
void DEFAULT_CC
xrdp_shutdown(int sig)
{
- tbus threadid;
-
- threadid = tc_get_threadid();
- g_writeln("shutting down");
- g_writeln("signal %d threadid %p", sig, threadid);
- if (!g_is_wait_obj_set(g_term_event))
- {
- g_set_wait_obj(g_term_event);
- }
+ tbus threadid;
+
+ threadid = tc_get_threadid();
+ g_writeln("shutting down");
+ g_writeln("signal %d threadid %p", sig, threadid);
+
+ if (!g_is_wait_obj_set(g_term_event))
+ {
+ g_set_wait_obj(g_term_event);
+ }
}
/*****************************************************************************/
int APP_CC
g_is_term(void)
{
- return g_is_wait_obj_set(g_term_event);
+ return g_is_wait_obj_set(g_term_event);
}
/*****************************************************************************/
void APP_CC
g_set_term(int in_val)
{
- if (in_val)
- {
- g_set_wait_obj(g_term_event);
- }
- else
- {
- g_reset_wait_obj(g_term_event);
- }
+ if (in_val)
+ {
+ g_set_wait_obj(g_term_event);
+ }
+ else
+ {
+ g_reset_wait_obj(g_term_event);
+ }
}
/*****************************************************************************/
tbus APP_CC
g_get_term_event(void)
{
- return g_term_event;
+ return g_term_event;
}
/*****************************************************************************/
tbus APP_CC
g_get_sync_event(void)
{
- return g_sync_event;
+ return g_sync_event;
}
/*****************************************************************************/
void DEFAULT_CC
pipe_sig(int sig_num)
{
- /* do nothing */
- g_writeln("got SIGPIPE(%d)", sig_num);
+ /* do nothing */
+ g_writeln("got SIGPIPE(%d)", sig_num);
}
/*****************************************************************************/
void APP_CC
g_process_waiting_function(void)
{
- tc_mutex_lock(g_sync_mutex);
- if (g_sync_command != 0)
- {
- if (g_sync_func != 0)
+ tc_mutex_lock(g_sync_mutex);
+
+ if (g_sync_command != 0)
{
- if (g_sync_command == 100)
- {
- g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
- }
+ if (g_sync_func != 0)
+ {
+ if (g_sync_command == 100)
+ {
+ g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
+ }
+ }
+
+ g_sync_command = 0;
}
- g_sync_command = 0;
- }
- tc_mutex_unlock(g_sync_mutex);
+
+ tc_mutex_unlock(g_sync_mutex);
}
/* win32 service control functions */
@@ -164,444 +169,484 @@ g_process_waiting_function(void)
VOID WINAPI
MyHandler(DWORD fdwControl)
{
- if (g_ssh == 0)
- {
- return;
- }
- if (fdwControl == SERVICE_CONTROL_STOP)
- {
- g_service_status.dwCurrentState = SERVICE_STOP_PENDING;
- g_set_term(1);
- }
- else if (fdwControl == SERVICE_CONTROL_PAUSE)
- {
- /* shouldn't happen */
- }
- else if (fdwControl == SERVICE_CONTROL_CONTINUE)
- {
- /* shouldn't happen */
- }
- else if (fdwControl == SERVICE_CONTROL_INTERROGATE)
- {
- }
- else if (fdwControl == SERVICE_CONTROL_SHUTDOWN)
- {
- g_service_status.dwCurrentState = SERVICE_STOP_PENDING;
- g_set_term(1);
- }
- SetServiceStatus(g_ssh, &g_service_status);
+ if (g_ssh == 0)
+ {
+ return;
+ }
+
+ if (fdwControl == SERVICE_CONTROL_STOP)
+ {
+ g_service_status.dwCurrentState = SERVICE_STOP_PENDING;
+ g_set_term(1);
+ }
+ else if (fdwControl == SERVICE_CONTROL_PAUSE)
+ {
+ /* shouldn't happen */
+ }
+ else if (fdwControl == SERVICE_CONTROL_CONTINUE)
+ {
+ /* shouldn't happen */
+ }
+ else if (fdwControl == SERVICE_CONTROL_INTERROGATE)
+ {
+ }
+ else if (fdwControl == SERVICE_CONTROL_SHUTDOWN)
+ {
+ g_service_status.dwCurrentState = SERVICE_STOP_PENDING;
+ g_set_term(1);
+ }
+
+ SetServiceStatus(g_ssh, &g_service_status);
}
/*****************************************************************************/
static void DEFAULT_CC
-log_event(HANDLE han, char* msg)
+log_event(HANDLE han, char *msg)
{
- ReportEvent(han, EVENTLOG_INFORMATION_TYPE, 0, 0, 0, 1, 0, &msg, 0);
+ ReportEvent(han, EVENTLOG_INFORMATION_TYPE, 0, 0, 0, 1, 0, &msg, 0);
}
/*****************************************************************************/
VOID WINAPI
-MyServiceMain(DWORD dwArgc, LPTSTR* lpszArgv)
+MyServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
{
- WSADATA w;
- char text[256];
- int pid;
- //HANDLE event_han;
-// int fd;
-// char text[256];
-
-// fd = g_file_open("c:\\temp\\xrdp\\log.txt");
-// g_file_write(fd, "hi\r\n", 4);
- //event_han = RegisterEventSource(0, "xrdp");
- //log_event(event_han, "hi xrdp log");
- g_threadid = tc_get_threadid();
- g_set_current_dir("c:\\temp\\xrdp");
- g_listen = 0;
- WSAStartup(2, &w);
- g_sync_mutex = tc_mutex_create();
- g_sync1_mutex = tc_mutex_create();
- pid = g_getpid();
- g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
- g_term_event = g_create_wait_obj(text);
- g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
- g_sync_event = g_create_wait_obj(text);
- g_memset(&g_service_status, 0, sizeof(SERVICE_STATUS));
- g_service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
- g_service_status.dwCurrentState = SERVICE_RUNNING;
- g_service_status.dwControlsAccepted = SERVICE_CONTROL_INTERROGATE |
- SERVICE_ACCEPT_STOP |
- SERVICE_ACCEPT_SHUTDOWN;
- g_service_status.dwWin32ExitCode = NO_ERROR;
- g_service_status.dwServiceSpecificExitCode = 0;
- g_service_status.dwCheckPoint = 0;
- g_service_status.dwWaitHint = 0;
-// g_sprintf(text, "calling RegisterServiceCtrlHandler\r\n");
-// g_file_write(fd, text, g_strlen(text));
- g_ssh = RegisterServiceCtrlHandler("xrdp", MyHandler);
- if (g_ssh != 0)
- {
-// g_sprintf(text, "ok\r\n");
-// g_file_write(fd, text, g_strlen(text));
- SetServiceStatus(g_ssh, &g_service_status);
- g_listen = xrdp_listen_create();
- xrdp_listen_main_loop(g_listen);
- g_sleep(100);
- g_service_status.dwCurrentState = SERVICE_STOPPED;
- SetServiceStatus(g_ssh, &g_service_status);
- }
- else
- {
- //g_sprintf(text, "RegisterServiceCtrlHandler failed\r\n");
- //g_file_write(fd, text, g_strlen(text));
- }
- xrdp_listen_delete(g_listen);
- tc_mutex_delete(g_sync_mutex);
- tc_mutex_delete(g_sync1_mutex);
- g_destroy_wait_obj(g_term_event);
- g_destroy_wait_obj(g_sync_event);
- WSACleanup();
- //CloseHandle(event_han);
+ WSADATA w;
+ char text[256];
+ int pid;
+ //HANDLE event_han;
+ // int fd;
+ // char text[256];
+
+ // fd = g_file_open("c:\\temp\\xrdp\\log.txt");
+ // g_file_write(fd, "hi\r\n", 4);
+ //event_han = RegisterEventSource(0, "xrdp");
+ //log_event(event_han, "hi xrdp log");
+ g_threadid = tc_get_threadid();
+ g_set_current_dir("c:\\temp\\xrdp");
+ g_listen = 0;
+ WSAStartup(2, &w);
+ g_sync_mutex = tc_mutex_create();
+ g_sync1_mutex = tc_mutex_create();
+ pid = g_getpid();
+ g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
+ g_term_event = g_create_wait_obj(text);
+ g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
+ g_sync_event = g_create_wait_obj(text);
+ g_memset(&g_service_status, 0, sizeof(SERVICE_STATUS));
+ g_service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ g_service_status.dwCurrentState = SERVICE_RUNNING;
+ g_service_status.dwControlsAccepted = SERVICE_CONTROL_INTERROGATE |
+ SERVICE_ACCEPT_STOP |
+ SERVICE_ACCEPT_SHUTDOWN;
+ g_service_status.dwWin32ExitCode = NO_ERROR;
+ g_service_status.dwServiceSpecificExitCode = 0;
+ g_service_status.dwCheckPoint = 0;
+ g_service_status.dwWaitHint = 0;
+ // g_sprintf(text, "calling RegisterServiceCtrlHandler\r\n");
+ // g_file_write(fd, text, g_strlen(text));
+ g_ssh = RegisterServiceCtrlHandler("xrdp", MyHandler);
+
+ if (g_ssh != 0)
+ {
+ // g_sprintf(text, "ok\r\n");
+ // g_file_write(fd, text, g_strlen(text));
+ SetServiceStatus(g_ssh, &g_service_status);
+ g_listen = xrdp_listen_create();
+ xrdp_listen_main_loop(g_listen);
+ g_sleep(100);
+ g_service_status.dwCurrentState = SERVICE_STOPPED;
+ SetServiceStatus(g_ssh, &g_service_status);
+ }
+ else
+ {
+ //g_sprintf(text, "RegisterServiceCtrlHandler failed\r\n");
+ //g_file_write(fd, text, g_strlen(text));
+ }
+
+ xrdp_listen_delete(g_listen);
+ tc_mutex_delete(g_sync_mutex);
+ tc_mutex_delete(g_sync1_mutex);
+ g_destroy_wait_obj(g_term_event);
+ g_destroy_wait_obj(g_sync_event);
+ WSACleanup();
+ //CloseHandle(event_han);
}
#endif
/*****************************************************************************/
int DEFAULT_CC
-main(int argc, char** argv)
+main(int argc, char **argv)
{
- int test;
- int host_be;
+ int test;
+ int host_be;
#if defined(_WIN32)
- WSADATA w;
- SC_HANDLE sc_man;
- SC_HANDLE sc_ser;
- int run_as_service;
- SERVICE_TABLE_ENTRY te[2];
+ WSADATA w;
+ SC_HANDLE sc_man;
+ SC_HANDLE sc_ser;
+ int run_as_service;
+ SERVICE_TABLE_ENTRY te[2];
#else
- int pid;
- int fd;
- int no_daemon;
- char text[256];
- char pid_file[256];
+ int pid;
+ int fd;
+ int no_daemon;
+ char text[256];
+ char pid_file[256];
#endif
- g_init();
- ssl_init();
- /* check compiled endian with actual endian */
- test = 1;
- host_be = !((int)(*(unsigned char*)(&test)));
+ g_init();
+ ssl_init();
+ /* check compiled endian with actual endian */
+ test = 1;
+ host_be = !((int)(*(unsigned char *)(&test)));
#if defined(B_ENDIAN)
- if (!host_be)
+
+ if (!host_be)
#endif
#if defined(L_ENDIAN)
- if (host_be)
+ if (host_be)
#endif
- {
- g_writeln("endian wrong, edit arch.h");
- return 0;
- }
- /* check long, int and void* sizes */
- if (sizeof(int) != 4)
- {
- g_writeln("unusable int size, must be 4");
- return 0;
- }
- if (sizeof(long) != sizeof(void*))
- {
- g_writeln("long size must match void* size");
- return 0;
- }
- if (sizeof(long) != 4 && sizeof(long) != 8)
- {
- g_writeln("unusable long size, must be 4 or 8");
- return 0;
- }
- if (sizeof(tui64) != 8)
- {
- g_writeln("unusable tui64 size, must be 8");
- return 0;
- }
-#if defined(_WIN32)
- run_as_service = 1;
- if (argc == 2)
- {
- if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
- g_strncasecmp(argv[1], "--help", 255) == 0 ||
- g_strncasecmp(argv[1], "-h", 255) == 0)
+ {
+ g_writeln("endian wrong, edit arch.h");
+ return 0;
+ }
+
+ /* check long, int and void* sizes */
+ if (sizeof(int) != 4)
{
- g_writeln("");
- g_writeln("xrdp: A Remote Desktop Protocol server.");
- g_writeln("Copyright (C) Jay Sorg 2004-2011");
- g_writeln("See http://xrdp.sourceforge.net for more information.");
- g_writeln("");
- g_writeln("Usage: xrdp [options]");
- g_writeln(" -h: show help");
- g_writeln(" -install: install service");
- g_writeln(" -remove: remove service");
- g_writeln("");
- g_exit(0);
+ g_writeln("unusable int size, must be 4");
+ return 0;
}
- else if (g_strncasecmp(argv[1], "-install", 255) == 0 ||
- g_strncasecmp(argv[1], "--install", 255) == 0 ||
- g_strncasecmp(argv[1], "-i", 255) == 0)
+
+ if (sizeof(long) != sizeof(void *))
{
- /* open service manager */
- sc_man = OpenSCManager(0, 0, GENERIC_WRITE);
- if (sc_man == 0)
- {
- g_writeln("error OpenSCManager, do you have rights?");
- g_exit(0);
- }
- /* check if service is allready installed */
- sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);
- if (sc_ser == 0)
- {
- /* install service */
- CreateService(sc_man, "xrdp", "xrdp", SERVICE_ALL_ACCESS,
- SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
- SERVICE_ERROR_IGNORE, "c:\\temp\\xrdp\\xrdp.exe",
- 0, 0, 0, 0, 0);
-
- }
- else
- {
- g_writeln("error service is allready installed");
- CloseServiceHandle(sc_ser);
- CloseServiceHandle(sc_man);
- g_exit(0);
- }
- CloseServiceHandle(sc_man);
- g_exit(0);
+ g_writeln("long size must match void* size");
+ return 0;
}
- else if (g_strncasecmp(argv[1], "-remove", 255) == 0 ||
- g_strncasecmp(argv[1], "--remove", 255) == 0 ||
- g_strncasecmp(argv[1], "-r", 255) == 0)
+
+ if (sizeof(long) != 4 && sizeof(long) != 8)
{
- /* open service manager */
- sc_man = OpenSCManager(0, 0, GENERIC_WRITE);
- if (sc_man == 0)
- {
- g_writeln("error OpenSCManager, do you have rights?");
- g_exit(0);
- }
- /* check if service is allready installed */
- sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);
- if (sc_ser == 0)
- {
- g_writeln("error service is not installed");
- CloseServiceHandle(sc_man);
- g_exit(0);
- }
- DeleteService(sc_ser);
- CloseServiceHandle(sc_man);
- g_exit(0);
+ g_writeln("unusable long size, must be 4 or 8");
+ return 0;
}
- else
+
+ if (sizeof(tui64) != 8)
{
- g_writeln("Unknown Parameter");
- g_writeln("xrdp -h for help");
- g_writeln("");
- g_exit(0);
+ g_writeln("unusable tui64 size, must be 8");
+ return 0;
}
- }
- else if (argc > 1)
- {
- g_writeln("Unknown Parameter");
- g_writeln("xrdp -h for help");
- g_writeln("");
- g_exit(0);
- }
- if (run_as_service)
- {
- g_memset(&te, 0, sizeof(te));
- te[0].lpServiceName = "xrdp";
- te[0].lpServiceProc = MyServiceMain;
- StartServiceCtrlDispatcher(&te);
- g_exit(0);
- }
- WSAStartup(2, &w);
-#else /* _WIN32 */
- g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH);
- no_daemon = 0;
- if (argc == 2)
- {
- if ((g_strncasecmp(argv[1], "-kill", 255) == 0) ||
- (g_strncasecmp(argv[1], "--kill", 255) == 0) ||
- (g_strncasecmp(argv[1], "-k", 255) == 0))
+
+#if defined(_WIN32)
+ run_as_service = 1;
+
+ if (argc == 2)
{
- g_writeln("stopping xrdp");
- /* read the xrdp.pid file */
- fd = -1;
- if (g_file_exist(pid_file)) /* xrdp.pid */
- {
- fd = g_file_open(pid_file); /* xrdp.pid */
- }
- if (fd == -1)
- {
- g_writeln("problem opening to xrdp.pid");
- g_writeln("maybe its not running");
- }
- else
- {
- g_memset(text, 0, 32);
- g_file_read(fd, text, 31);
- pid = g_atoi(text);
- g_writeln("stopping process id %d", pid);
- if (pid > 0)
+ if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
+ g_strncasecmp(argv[1], "--help", 255) == 0 ||
+ g_strncasecmp(argv[1], "-h", 255) == 0)
{
- g_sigterm(pid);
+ g_writeln("");
+ g_writeln("xrdp: A Remote Desktop Protocol server.");
+ g_writeln("Copyright (C) Jay Sorg 2004-2011");
+ g_writeln("See http://xrdp.sourceforge.net for more information.");
+ g_writeln("");
+ g_writeln("Usage: xrdp [options]");
+ g_writeln(" -h: show help");
+ g_writeln(" -install: install service");
+ g_writeln(" -remove: remove service");
+ g_writeln("");
+ g_exit(0);
+ }
+ else if (g_strncasecmp(argv[1], "-install", 255) == 0 ||
+ g_strncasecmp(argv[1], "--install", 255) == 0 ||
+ g_strncasecmp(argv[1], "-i", 255) == 0)
+ {
+ /* open service manager */
+ sc_man = OpenSCManager(0, 0, GENERIC_WRITE);
+
+ if (sc_man == 0)
+ {
+ g_writeln("error OpenSCManager, do you have rights?");
+ g_exit(0);
+ }
+
+ /* check if service is allready installed */
+ sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);
+
+ if (sc_ser == 0)
+ {
+ /* install service */
+ CreateService(sc_man, "xrdp", "xrdp", SERVICE_ALL_ACCESS,
+ SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
+ SERVICE_ERROR_IGNORE, "c:\\temp\\xrdp\\xrdp.exe",
+ 0, 0, 0, 0, 0);
+
+ }
+ else
+ {
+ g_writeln("error service is allready installed");
+ CloseServiceHandle(sc_ser);
+ CloseServiceHandle(sc_man);
+ g_exit(0);
+ }
+
+ CloseServiceHandle(sc_man);
+ g_exit(0);
+ }
+ else if (g_strncasecmp(argv[1], "-remove", 255) == 0 ||
+ g_strncasecmp(argv[1], "--remove", 255) == 0 ||
+ g_strncasecmp(argv[1], "-r", 255) == 0)
+ {
+ /* open service manager */
+ sc_man = OpenSCManager(0, 0, GENERIC_WRITE);
+
+ if (sc_man == 0)
+ {
+ g_writeln("error OpenSCManager, do you have rights?");
+ g_exit(0);
+ }
+
+ /* check if service is allready installed */
+ sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);
+
+ if (sc_ser == 0)
+ {
+ g_writeln("error service is not installed");
+ CloseServiceHandle(sc_man);
+ g_exit(0);
+ }
+
+ DeleteService(sc_ser);
+ CloseServiceHandle(sc_man);
+ g_exit(0);
+ }
+ else
+ {
+ g_writeln("Unknown Parameter");
+ g_writeln("xrdp -h for help");
+ g_writeln("");
+ g_exit(0);
}
- g_file_close(fd);
- }
- g_exit(0);
}
- else if (g_strncasecmp(argv[1], "-nodaemon", 255) == 0 ||
- g_strncasecmp(argv[1], "--nodaemon", 255) == 0 ||
- g_strncasecmp(argv[1], "-nd", 255) == 0 ||
- g_strncasecmp(argv[1], "--nd", 255) == 0 ||
- g_strncasecmp(argv[1], "-ns", 255) == 0 ||
- g_strncasecmp(argv[1], "--ns", 255) == 0)
+ else if (argc > 1)
{
- no_daemon = 1;
+ g_writeln("Unknown Parameter");
+ g_writeln("xrdp -h for help");
+ g_writeln("");
+ g_exit(0);
}
- else if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
- g_strncasecmp(argv[1], "--help", 255) == 0 ||
- g_strncasecmp(argv[1], "-h", 255) == 0)
+
+ if (run_as_service)
{
- g_writeln("");
- g_writeln("xrdp: A Remote Desktop Protocol server.");
- g_writeln("Copyright (C) Jay Sorg 2004-2011");
- g_writeln("See http://xrdp.sourceforge.net for more information.");
- g_writeln("");
- g_writeln("Usage: xrdp [options]");
- g_writeln(" -h: show help");
- g_writeln(" -nodaemon: don't fork into background");
- g_writeln(" -kill: shut down xrdp");
- g_writeln("");
- g_exit(0);
+ g_memset(&te, 0, sizeof(te));
+ te[0].lpServiceName = "xrdp";
+ te[0].lpServiceProc = MyServiceMain;
+ StartServiceCtrlDispatcher(&te);
+ g_exit(0);
}
- else if ((g_strncasecmp(argv[1], "-v", 255) == 0) ||
- (g_strncasecmp(argv[1], "--version", 255) == 0))
+
+ WSAStartup(2, &w);
+#else /* _WIN32 */
+ g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH);
+ no_daemon = 0;
+
+ if (argc == 2)
{
- g_writeln("");
- g_writeln("xrdp: A Remote Desktop Protocol server.");
- g_writeln("Copyright (C) Jay Sorg 2004-2011");
- g_writeln("See http://xrdp.sourceforge.net for more information.");
- g_writeln("Version %s",PACKAGE_VERSION);
- g_writeln("");
- g_exit(0);
+ if ((g_strncasecmp(argv[1], "-kill", 255) == 0) ||
+ (g_strncasecmp(argv[1], "--kill", 255) == 0) ||
+ (g_strncasecmp(argv[1], "-k", 255) == 0))
+ {
+ g_writeln("stopping xrdp");
+ /* read the xrdp.pid file */
+ fd = -1;
+
+ if (g_file_exist(pid_file)) /* xrdp.pid */
+ {
+ fd = g_file_open(pid_file); /* xrdp.pid */
+ }
+
+ if (fd == -1)
+ {
+ g_writeln("problem opening to xrdp.pid");
+ g_writeln("maybe its not running");
+ }
+ else
+ {
+ g_memset(text, 0, 32);
+ g_file_read(fd, text, 31);
+ pid = g_atoi(text);
+ g_writeln("stopping process id %d", pid);
+
+ if (pid > 0)
+ {
+ g_sigterm(pid);
+ }
+
+ g_file_close(fd);
+ }
+
+ g_exit(0);
+ }
+ else if (g_strncasecmp(argv[1], "-nodaemon", 255) == 0 ||
+ g_strncasecmp(argv[1], "--nodaemon", 255) == 0 ||
+ g_strncasecmp(argv[1], "-nd", 255) == 0 ||
+ g_strncasecmp(argv[1], "--nd", 255) == 0 ||
+ g_strncasecmp(argv[1], "-ns", 255) == 0 ||
+ g_strncasecmp(argv[1], "--ns", 255) == 0)
+ {
+ no_daemon = 1;
+ }
+ else if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
+ g_strncasecmp(argv[1], "--help", 255) == 0 ||
+ g_strncasecmp(argv[1], "-h", 255) == 0)
+ {
+ g_writeln("");
+ g_writeln("xrdp: A Remote Desktop Protocol server.");
+ g_writeln("Copyright (C) Jay Sorg 2004-2011");
+ g_writeln("See http://xrdp.sourceforge.net for more information.");
+ g_writeln("");
+ g_writeln("Usage: xrdp [options]");
+ g_writeln(" -h: show help");
+ g_writeln(" -nodaemon: don't fork into background");
+ g_writeln(" -kill: shut down xrdp");
+ g_writeln("");
+ g_exit(0);
+ }
+ else if ((g_strncasecmp(argv[1], "-v", 255) == 0) ||
+ (g_strncasecmp(argv[1], "--version", 255) == 0))
+ {
+ g_writeln("");
+ g_writeln("xrdp: A Remote Desktop Protocol server.");
+ g_writeln("Copyright (C) Jay Sorg 2004-2011");
+ g_writeln("See http://xrdp.sourceforge.net for more information.");
+ g_writeln("Version %s", PACKAGE_VERSION);
+ g_writeln("");
+ g_exit(0);
+ }
+ else
+ {
+ g_writeln("Unknown Parameter");
+ g_writeln("xrdp -h for help");
+ g_writeln("");
+ g_exit(0);
+ }
}
- else
+ else if (argc > 1)
{
- g_writeln("Unknown Parameter");
- g_writeln("xrdp -h for help");
- g_writeln("");
- g_exit(0);
+ g_writeln("Unknown Parameter");
+ g_writeln("xrdp -h for help");
+ g_writeln("");
+ g_exit(0);
}
- }
- else if (argc > 1)
- {
- g_writeln("Unknown Parameter");
- g_writeln("xrdp -h for help");
- g_writeln("");
- g_exit(0);
- }
- if (g_file_exist(pid_file)) /* xrdp.pid */
- {
- g_writeln("It looks like xrdp is allready running,");
- g_writeln("if not delete the xrdp.pid file and try again");
- g_exit(0);
- }
- if (!no_daemon)
- {
- /* make sure we can write to pid file */
- fd = g_file_open(pid_file); /* xrdp.pid */
- if (fd == -1)
+
+ if (g_file_exist(pid_file)) /* xrdp.pid */
{
- g_writeln("running in daemon mode with no access to pid files, quitting");
- g_exit(0);
+ g_writeln("It looks like xrdp is allready running,");
+ g_writeln("if not delete the xrdp.pid file and try again");
+ g_exit(0);
}
- if (g_file_write(fd, "0", 1) == -1)
+
+ if (!no_daemon)
{
- g_writeln("running in daemon mode with no access to pid files, quitting");
- g_exit(0);
+ /* make sure we can write to pid file */
+ fd = g_file_open(pid_file); /* xrdp.pid */
+
+ if (fd == -1)
+ {
+ g_writeln("running in daemon mode with no access to pid files, quitting");
+ g_exit(0);
+ }
+
+ if (g_file_write(fd, "0", 1) == -1)
+ {
+ g_writeln("running in daemon mode with no access to pid files, quitting");
+ g_exit(0);
+ }
+
+ g_file_close(fd);
+ g_file_delete(pid_file);
}
- g_file_close(fd);
- g_file_delete(pid_file);
- }
- if (!no_daemon)
- {
- /* start of daemonizing code */
- pid = g_fork();
- if (pid == -1)
+
+ if (!no_daemon)
{
- g_writeln("problem forking");
- g_exit(1);
+ /* start of daemonizing code */
+ pid = g_fork();
+
+ if (pid == -1)
+ {
+ g_writeln("problem forking");
+ g_exit(1);
+ }
+
+ if (0 != pid)
+ {
+ g_writeln("process %d started ok", pid);
+ /* exit, this is the main process */
+ g_exit(0);
+ }
+
+ g_sleep(1000);
+ g_file_close(0);
+ g_file_close(1);
+ g_file_close(2);
+ g_file_open("/dev/null");
+ g_file_open("/dev/null");
+ g_file_open("/dev/null");
+ /* end of daemonizing code */
}
- if (0 != pid)
+
+ if (!no_daemon)
{
- g_writeln("process %d started ok", pid);
- /* exit, this is the main process */
- g_exit(0);
+ /* write the pid to file */
+ pid = g_getpid();
+ fd = g_file_open(pid_file); /* xrdp.pid */
+
+ if (fd == -1)
+ {
+ g_writeln("trying to write process id to xrdp.pid");
+ g_writeln("problem opening xrdp.pid");
+ g_writeln("maybe no rights");
+ }
+ else
+ {
+ g_sprintf(text, "%d", pid);
+ g_file_write(fd, text, g_strlen(text));
+ g_file_close(fd);
+ }
}
- g_sleep(1000);
- g_file_close(0);
- g_file_close(1);
- g_file_close(2);
- g_file_open("/dev/null");
- g_file_open("/dev/null");
- g_file_open("/dev/null");
- /* end of daemonizing code */
- }
- if (!no_daemon)
- {
- /* write the pid to file */
+
+#endif
+ g_threadid = tc_get_threadid();
+ g_listen = xrdp_listen_create();
+ g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
+ g_signal_kill(xrdp_shutdown); /* SIGKILL */
+ g_signal_pipe(pipe_sig); /* SIGPIPE */
+ g_signal_terminate(xrdp_shutdown); /* SIGTERM */
+ g_sync_mutex = tc_mutex_create();
+ g_sync1_mutex = tc_mutex_create();
pid = g_getpid();
- fd = g_file_open(pid_file); /* xrdp.pid */
- if (fd == -1)
- {
- g_writeln("trying to write process id to xrdp.pid");
- g_writeln("problem opening xrdp.pid");
- g_writeln("maybe no rights");
- }
- else
+ g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
+ g_term_event = g_create_wait_obj(text);
+ g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
+ g_sync_event = g_create_wait_obj(text);
+
+ if (g_term_event == 0)
{
- g_sprintf(text, "%d", pid);
- g_file_write(fd, text, g_strlen(text));
- g_file_close(fd);
+ g_writeln("error creating g_term_event");
}
- }
-#endif
- g_threadid = tc_get_threadid();
- g_listen = xrdp_listen_create();
- g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
- g_signal_kill(xrdp_shutdown); /* SIGKILL */
- g_signal_pipe(pipe_sig); /* SIGPIPE */
- g_signal_terminate(xrdp_shutdown); /* SIGTERM */
- g_sync_mutex = tc_mutex_create();
- g_sync1_mutex = tc_mutex_create();
- pid = g_getpid();
- g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
- g_term_event = g_create_wait_obj(text);
- g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
- g_sync_event = g_create_wait_obj(text);
- if (g_term_event == 0)
- {
- g_writeln("error creating g_term_event");
- }
- xrdp_listen_main_loop(g_listen);
- xrdp_listen_delete(g_listen);
- tc_mutex_delete(g_sync_mutex);
- tc_mutex_delete(g_sync1_mutex);
- g_delete_wait_obj(g_term_event);
- g_delete_wait_obj(g_sync_event);
+
+ xrdp_listen_main_loop(g_listen);
+ xrdp_listen_delete(g_listen);
+ tc_mutex_delete(g_sync_mutex);
+ tc_mutex_delete(g_sync1_mutex);
+ g_delete_wait_obj(g_term_event);
+ g_delete_wait_obj(g_sync_event);
#if defined(_WIN32)
- /* I don't think it ever gets here */
- /* when running in win32 app mode, control c exits right away */
- WSACleanup();
+ /* I don't think it ever gets here */
+ /* when running in win32 app mode, control c exits right away */
+ WSACleanup();
#else
- /* delete the xrdp.pid file */
- g_file_delete(pid_file);
+ /* delete the xrdp.pid file */
+ g_file_delete(pid_file);
#endif
- return 0;
+ return 0;
}
-