2 * FreeRDP: A Remote Desktop Protocol Client
3 * Remote Applications Integrated Locally (RAIL) Utils
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <freerdp/types.h>
21 #include <freerdp/utils/memory.h>
23 #include <freerdp/utils/rail.h>
24 #include <freerdp/rail.h>
26 void rail_unicode_string_alloc(UNICODE_STRING* unicode_string, uint16 cbString)
28 unicode_string->length = cbString;
29 unicode_string->string = xzalloc(cbString);
32 void rail_unicode_string_free(UNICODE_STRING* unicode_string)
34 unicode_string->length = 0;
36 if (unicode_string->string != NULL)
37 xfree(unicode_string->string);
40 void rail_read_unicode_string(STREAM* s, UNICODE_STRING* unicode_string)
42 stream_read_uint16(s, unicode_string->length); /* cbString (2 bytes) */
44 if (unicode_string->string == NULL)
45 unicode_string->string = (uint8*) xmalloc(unicode_string->length);
47 unicode_string->string = (uint8*) xrealloc(unicode_string->string, unicode_string->length);
49 stream_read(s, unicode_string->string, unicode_string->length);
52 void rail_write_unicode_string(STREAM* s, UNICODE_STRING* unicode_string)
54 stream_check_size(s, 2 + unicode_string->length);
55 stream_write_uint16(s, unicode_string->length); /* cbString (2 bytes) */
56 stream_write(s, unicode_string->string, unicode_string->length); /* string */
59 void rail_write_unicode_string_value(STREAM* s, UNICODE_STRING* unicode_string)
61 if (unicode_string->length > 0)
63 stream_check_size(s, unicode_string->length);
64 stream_write(s, unicode_string->string, unicode_string->length); /* string */
68 void rail_read_rectangle_16(STREAM* s, RECTANGLE_16* rectangle_16)
70 stream_read_uint16(s, rectangle_16->left); /* left (2 bytes) */
71 stream_read_uint16(s, rectangle_16->top); /* top (2 bytes) */
72 stream_read_uint16(s, rectangle_16->right); /* right (2 bytes) */
73 stream_read_uint16(s, rectangle_16->bottom); /* bottom (2 bytes) */
76 void rail_write_rectangle_16(STREAM* s, RECTANGLE_16* rectangle_16)
78 stream_write_uint16(s, rectangle_16->left); /* left (2 bytes) */
79 stream_write_uint16(s, rectangle_16->top); /* top (2 bytes) */
80 stream_write_uint16(s, rectangle_16->right); /* right (2 bytes) */
81 stream_write_uint16(s, rectangle_16->bottom); /* bottom (2 bytes) */
84 void* rail_clone_order(uint32 event_type, void* order)
92 {RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS, sizeof(RAIL_SYSPARAM_ORDER)},
93 {RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS, sizeof(RAIL_EXEC_RESULT_ORDER)},
94 {RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM, sizeof(RAIL_SYSPARAM_ORDER)},
95 {RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO, sizeof(RAIL_MINMAXINFO_ORDER)},
96 {RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE, sizeof(RAIL_LOCALMOVESIZE_ORDER)},
97 {RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP, sizeof(RAIL_GET_APPID_RESP_ORDER)},
98 {RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO, sizeof(RAIL_LANGBAR_INFO_ORDER)},
99 {RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, sizeof(RAIL_SYSPARAM_ORDER)},
100 {RDP_EVENT_TYPE_RAIL_CLIENT_EXEC_REMOTE_APP, sizeof(RDP_PLUGIN_DATA)},
101 {RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE, sizeof(RAIL_ACTIVATE_ORDER)},
102 {RDP_EVENT_TYPE_RAIL_CLIENT_SYSMENU, sizeof(RAIL_SYSMENU_ORDER)},
103 {RDP_EVENT_TYPE_RAIL_CLIENT_SYSCOMMAND, sizeof(RAIL_SYSCOMMAND_ORDER)},
104 {RDP_EVENT_TYPE_RAIL_CLIENT_NOTIFY_EVENT, sizeof(RAIL_NOTIFY_EVENT_ORDER)},
105 {RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, sizeof(RAIL_WINDOW_MOVE_ORDER)},
106 {RDP_EVENT_TYPE_RAIL_CLIENT_APPID_REQ, sizeof(RAIL_GET_APPID_REQ_ORDER)},
107 {RDP_EVENT_TYPE_RAIL_CLIENT_LANGBARINFO, sizeof(RAIL_LANGBAR_INFO_ORDER)},
110 size_t order_size = 0;
111 void* new_order = NULL;
113 for (i = 0; i < RAIL_ARRAY_SIZE(ordersize_table); i++)
115 if (event_type == ordersize_table[i].type)
117 order_size = ordersize_table[i].size;
122 // Event type not found.
123 if (order_size == 0) return NULL;
125 new_order = xmalloc(order_size);
126 memcpy(new_order, order, order_size);
128 //printf("rail_clone_order: type=%d order=%p\n", event_type, new_order);
130 // Create copy of variable data for some orders
131 if ((event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS) ||
132 (event_type == RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS))
134 RAIL_SYSPARAM_ORDER* new_sysparam = (RAIL_SYSPARAM_ORDER*)new_order;
135 RAIL_SYSPARAM_ORDER* old_sysparam = (RAIL_SYSPARAM_ORDER*)order;
137 rail_unicode_string_alloc(&new_sysparam->highContrast.colorScheme,
138 old_sysparam->highContrast.colorScheme.length);
140 memcpy(new_sysparam->highContrast.colorScheme.string,
141 old_sysparam->highContrast.colorScheme.string,
142 old_sysparam->highContrast.colorScheme.length);
145 if (event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS)
147 RAIL_EXEC_RESULT_ORDER* new_exec_result = (RAIL_EXEC_RESULT_ORDER*)new_order;
148 RAIL_EXEC_RESULT_ORDER* old_exec_result = (RAIL_EXEC_RESULT_ORDER*)order;
150 rail_unicode_string_alloc(&new_exec_result->exeOrFile,
151 old_exec_result->exeOrFile.length);
153 memcpy(new_exec_result->exeOrFile.string,
154 old_exec_result->exeOrFile.string,
155 old_exec_result->exeOrFile.length);
158 if (event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP)
160 RAIL_GET_APPID_RESP_ORDER* new_app_resp = (RAIL_GET_APPID_RESP_ORDER*)new_order;
162 new_app_resp->applicationId.string = &new_app_resp->applicationIdBuffer[0];
168 void rail_free_cloned_order(uint32 event_type, void* order)
170 //printf("rail_free_cloned_order: type=%d order=%p\n", event_type, order);
171 if ((event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS) ||
172 (event_type == RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS))
174 RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*)order;
175 rail_unicode_string_free(&sysparam->highContrast.colorScheme);
178 if (event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS)
180 RAIL_EXEC_RESULT_ORDER* exec_result = (RAIL_EXEC_RESULT_ORDER*)order;
181 rail_unicode_string_free(&exec_result->exeOrFile);