1 /**
2  * FreeRDP: A Remote Desktop Protocol Server
3  * freerdp wrapper
4  *
5  * Copyright 2011-2013 Jay Sorg
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 /* include other h files */
21 #include "arch.h"
22 #include "parse.h"
23 #include "os_calls.h"
24 #include "defines.h"
25 #include "xrdp_rail.h"
26 #include "xrdp_client_info.h"
27 #include "xrdp_constants.h"
28 
29 /* this is the freerdp main header */
30 #include <freerdp/freerdp.h>
31 #include <freerdp/rail.h>
32 #include <freerdp/rail/rail.h>
33 #include <freerdp/codec/bitmap.h>
34 //#include <freerdp/utils/memory.h>
35 //#include "/home/jay/git/jsorg71/staging/include/freerdp/freerdp.h"
36 
37 struct bitmap_item
38 {
39     int width;
40     int height;
41     char *data;
42 };
43 
44 struct brush_item
45 {
46     int bpp;
47     int width;
48     int height;
49     char *data;
50     char b8x8[8];
51 };
52 
53 struct pointer_item
54 {
55     int hotx;
56     int hoty;
57     char data[32 * 32 * 4];
58     char mask[32 * 32 / 8];
59     int bpp;
60 };
61 
62 #define CURRENT_MOD_VER 4
63 
64 struct source_info;
65 
66 struct mod
67 {
68     int size; /* size of this struct */
69     int version; /* internal version */
70     /* client functions */
71     int (*mod_start)(struct mod *v, int w, int h, int bpp);
72     int (*mod_connect)(struct mod *v);
73     int (*mod_event)(struct mod *v, int msg, long param1, long param2,
74                      long param3, long param4);
75     int (*mod_signal)(struct mod *v);
76     int (*mod_end)(struct mod *v);
77     int (*mod_set_param)(struct mod *v, const char *name, const char *value);
78     int (*mod_session_change)(struct mod *v, int, int);
79     int (*mod_get_wait_objs)(struct mod *v, tbus *read_objs, int *rcount,
80                              tbus *write_objs, int *wcount, int *timeout);
81     int (*mod_check_wait_objs)(struct mod *v);
82     int (*mod_frame_ack)(struct mod *mod, int flags, int frame_id);
83     int (*mod_suppress_output)(struct mod *mod, int suppress,
84                                int left, int top, int right, int bottom);
85     int (*mod_server_monitor_resize)(struct mod *mod,
86                                int width, int height);
87     int (*mod_server_monitor_full_invalidate)(struct mod *mod,
88                                int width, int height);
89     int (*mod_server_version_message)(struct mod *mod);
90     tintptr mod_dumby[100 - 14]; /* align, 100 minus the number of mod
91                                  functions above */
92     /* server functions */
93     int (*server_begin_update)(struct mod *v);
94     int (*server_end_update)(struct mod *v);
95     int (*server_fill_rect)(struct mod *v, int x, int y, int cx, int cy);
96     int (*server_screen_blt)(struct mod *v, int x, int y, int cx, int cy,
97                              int srcx, int srcy);
98     int (*server_paint_rect)(struct mod *v, int x, int y, int cx, int cy,
99                              char *data, int width, int height, int srcx, int srcy);
100     int (*server_set_pointer)(struct mod *v, int x, int y, char *data, char *mask);
101     int (*server_palette)(struct mod *v, int *palette);
102     int (*server_msg)(struct mod *v, char *msg, int code);
103     int (*server_is_term)(struct mod *v);
104     int (*server_set_clip)(struct mod *v, int x, int y, int cx, int cy);
105     int (*server_reset_clip)(struct mod *v);
106     int (*server_set_fgcolor)(struct mod *v, int fgcolor);
107     int (*server_set_bgcolor)(struct mod *v, int bgcolor);
108     int (*server_set_opcode)(struct mod *v, int opcode);
109     int (*server_set_mixmode)(struct mod *v, int mixmode);
110     int (*server_set_brush)(struct mod *v, int x_origin, int y_origin,
111                             int style, char *pattern);
112     int (*server_set_pen)(struct mod *v, int style,
113                           int width);
114     int (*server_draw_line)(struct mod *v, int x1, int y1, int x2, int y2);
115     int (*server_add_char)(struct mod *v, int font, int character,
116                            int offset, int baseline,
117                            int width, int height, char *data);
118     int (*server_draw_text)(struct mod *v, int font,
119                             int flags, int mixmode, int clip_left, int clip_top,
120                             int clip_right, int clip_bottom,
121                             int box_left, int box_top,
122                             int box_right, int box_bottom,
123                             int x, int y, char *data, int data_len);
124     int (*server_reset)(struct mod *v, int width, int height, int bpp);
125     int (*server_query_channel)(struct mod *v, int index,
126                                 char *channel_name,
127                                 int *channel_flags);
128     int (*server_get_channel_id)(struct mod *v, const char *name);
129     int (*server_send_to_channel)(struct mod *v, int channel_id,
130                                   char *data, int data_len,
131                                   int total_data_len, int flags);
132     int (*server_bell_trigger)(struct mod *v);
133     /* off screen bitmaps */
134     int (*server_create_os_surface)(struct mod *v, int rdpindex,
135                                     int width, int height);
136     int (*server_switch_os_surface)(struct mod *v, int rdpindex);
137     int (*server_delete_os_surface)(struct mod *v, int rdpindex);
138     int (*server_paint_rect_os)(struct mod *mod, int x, int y,
139                                 int cx, int cy,
140                                 int rdpindex, int srcx, int srcy);
141     int (*server_set_hints)(struct mod *mod, int hints, int mask);
142     /* rail */
143     int (*server_window_new_update)(struct mod *mod, int window_id,
144                                     struct rail_window_state_order *window_state,
145                                     int flags);
146     int (*server_window_delete)(struct mod *mod, int window_id);
147     int (*server_window_icon)(struct mod *mod,
148                               int window_id, int cache_entry, int cache_id,
149                               struct rail_icon_info *icon_info,
150                               int flags);
151     int (*server_window_cached_icon)(struct mod *mod,
152                                      int window_id, int cache_entry,
153                                      int cache_id, int flags);
154     int (*server_notify_new_update)(struct mod *mod,
155                                     int window_id, int notify_id,
156                                     struct rail_notify_state_order *notify_state,
157                                     int flags);
158     int (*server_notify_delete)(struct mod *mod, int window_id,
159                                 int notify_id);
160     int (*server_monitored_desktop)(struct mod *mod,
161                                     struct rail_monitored_desktop_order *mdo,
162                                     int flags);
163     int (*server_set_pointer_ex)(struct mod *mod, int x, int y, char *data,
164                                  char *mask, int bpp);
165     int (*server_add_char_alpha)(struct mod *mod, int font, int character,
166                                  int offset, int baseline,
167                                  int width, int height, char *data);
168     int (*server_create_os_surface_bpp)(struct mod *v, int rdpindex,
169                                         int width, int height, int bpp);
170     int (*server_paint_rect_bpp)(struct mod *v, int x, int y, int cx, int cy,
171                                  char *data, int width, int height,
172                                  int srcx, int srcy, int bpp);
173     int (*server_composite)(struct mod *v, int srcidx, int srcformat,
174                             int srcwidth, int srcrepeat, int *srctransform,
175                             int mskflags, int mskidx, int mskformat,
176                             int mskwidth, int mskrepeat, int op,
177                             int srcx, int srcy, int mskx, int msky,
178                             int dstx, int dsty, int width, int height,
179                             int dstformat);
180     int (*server_paint_rects)(struct mod *v,
181                               int num_drects, short *drects,
182                               int num_crects, short *crects,
183                               char *data, int width, int height,
184                               int flags, int frame_id);
185     int (*server_session_info)(struct mod *v, const char *data,
186                                int data_bytes);
187     tintptr server_dumby[100 - 44]; /* align, 100 minus the number of server
188                                        functions above */
189     /* common */
190     tintptr handle; /* pointer to self as long */
191     tintptr wm;
192     tintptr painter;
193     struct source_info *si;
194 
195     /* mod data */
196     int sck;
197     int width;
198     int height;
199     int bpp;
200     int colormap[256];
201     char *chan_buf;
202     int chan_buf_valid;
203     int chan_buf_bytes;
204     int vmaj;
205     int vmin;
206     int vrev;
207     char username[INFO_CLIENT_MAX_CB_LEN];
208     char password[INFO_CLIENT_MAX_CB_LEN];
209     char domain[INFO_CLIENT_MAX_CB_LEN];
210     int bool_keyBoardSynced ; /* Numlock can be out of sync, we hold state here to resolve */
211     int keyBoardLockInfo ; /* Holds initial numlock capslock state */
212 
213     struct xrdp_client_info client_info;
214 
215     struct rdp_freerdp *inst;
216     struct bitmap_item bitmap_cache[4][4096];
217     struct brush_item brush_cache[64];
218     struct pointer_item pointer_cache[32];
219 
220 };
221