libfreerdp-core: started input PDUs

This commit is contained in:
Marc-André Moreau 2011-07-27 20:14:12 -04:00
parent e344149109
commit fa41f16a81
4 changed files with 236 additions and 2 deletions

View File

@ -34,6 +34,8 @@ set(LIBFREERDP_CORE_SRCS
nego.h
info.c
info.h
input.c
input.h
crypto.c
crypto.h
credssp.c

141
libfreerdp-core/input.c Normal file
View File

@ -0,0 +1,141 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Input PDUs
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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.
*/
#include "input.h"
void rdp_write_client_input_pdu_header(STREAM* s, uint16 number)
{
stream_write_uint16(s, 1); /* numberEvents (2 bytes) */
stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
}
STREAM* rdp_client_input_pdu_init(rdpRdp* rdp)
{
STREAM* s;
s = rdp_data_pdu_init(rdp);
rdp_write_client_input_pdu_header(s, 1);
return s;
}
void rdp_send_client_input_pdu(rdpRdp* rdp, STREAM* s)
{
rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_INPUT, rdp->mcs->user_id);
}
void input_write_synchronize_event(STREAM* s, uint32 flags)
{
stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
stream_write_uint32(s, flags); /* toggleFlags (4 bytes) */
}
void input_send_synchronize_event(rdpInput* input, uint32 flags)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
input_write_synchronize_event(s, flags);
rdp_send_client_input_pdu(input->rdp, s);
}
void input_write_keyboard_event(STREAM* s, uint16 flags, uint16 code)
{
stream_write_uint16(s, flags); /* keyboardFlags (2 bytes) */
stream_write_uint16(s, code); /* keyCode (2 bytes) */
stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
}
void input_send_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
input_write_keyboard_event(s, flags, code);
rdp_send_client_input_pdu(input->rdp, s);
}
void input_write_unicode_keyboard_event(STREAM* s, uint16 code)
{
stream_write_uint16(s, 0); /* pad2OctetsA (2 bytes) */
stream_write_uint16(s, code); /* unicodeCode (2 bytes) */
stream_write_uint16(s, 0); /* pad2OctetsB (2 bytes) */
}
void input_send_unicode_keyboard_event(rdpInput* input, uint16 code)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
input_write_unicode_keyboard_event(s, code);
rdp_send_client_input_pdu(input->rdp, s);
}
void input_write_mouse_event(STREAM* s, uint16 flags, uint16 x, uint16 y)
{
stream_write_uint16(s, flags); /* pointerFlags (2 bytes) */
stream_write_uint16(s, x); /* xPos (2 bytes) */
stream_write_uint16(s, y); /* yPos (2 bytes) */
}
void input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
input_write_mouse_event(s, flags, x, y);
rdp_send_client_input_pdu(input->rdp, s);
}
void input_write_extended_mouse_event(STREAM* s, uint16 flags, uint16 x, uint16 y)
{
stream_write_uint16(s, flags); /* pointerFlags (2 bytes) */
stream_write_uint16(s, x); /* xPos (2 bytes) */
stream_write_uint16(s, y); /* yPos (2 bytes) */
}
void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
STREAM* s;
s = rdp_client_input_pdu_init(input->rdp);
input_write_extended_mouse_event(s, flags, x, y);
rdp_send_client_input_pdu(input->rdp, s);
}
rdpInput* input_new(rdpRdp* rdp)
{
rdpInput* input;
input = (rdpInput*) xzalloc(sizeof(rdpInput));
if (input != NULL)
{
input->rdp = rdp;
input->SynchronizeEvent = input_send_synchronize_event;
input->KeyboardEvent = input_send_keyboard_event;
input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event;
input->MouseEvent = input_send_mouse_event;
input->ExtendedMouseEvent = input_send_extended_mouse_event;
}
return input;
}
void input_free(rdpInput* input)
{
if (input != NULL)
{
xfree(input);
}
}

91
libfreerdp-core/input.h Normal file
View File

@ -0,0 +1,91 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Input PDUs
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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.
*/
#ifndef __INPUT_H
#define __INPUT_H
#include "rdp.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/memory.h>
/* Input Events */
#define INPUT_EVENT_SYNC 0x0000
#define INPUT_EVENT_SCANCODE 0x0004
#define INPUT_EVENT_UNICODE 0x0005
#define INPUT_EVENT_MOUSE 0x8001
#define INPUT_EVENT_MOUSEX 0x8002
/* keyboard Flags */
#define KBD_FLAGS_EXTENDED 0x0100
#define KBD_FLAGS_DOWN 0x4000
#define KBD_FLAGS_RELEASE 0x8000
/* Pointer Flags */
#define PTR_FLAGS_WHEEL 0x0200
#define PTR_FLAGS_WHEEL_NEGATIVE 0x0100
#define PTR_FLAGS_MOVE 0x0800
#define PTR_FLAGS_DOWN 0x8000
#define PTR_FLAGS_BUTTON1 0x1000
#define PTR_FLAGS_BUTTON2 0x2000
#define PTR_FLAGS_BUTTON3 0x4000
#define WheelRotationMask 0x01FF
/* Extended Pointer Flags */
#define PTR_XFLAGS_DOWN 0x8000
#define PTR_XFLAGS_BUTTON1 0x0001
#define PTR_XFLAGS_BUTTON2 0x0002
/* Keyboard Toggle Flags */
#define KBD_SYNC_SCROLL_LOCK 0x00000001
#define KBD_SYNC_NUM_LOCK 0x00000002
#define KBD_SYNC_CAPS_LOCK 0x00000004
#define KBD_SYNC_KANA_LOCK 0x00000008
#define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4
typedef struct rdp_input rdpInput;
typedef void (*pcSynchronizeEvent)(rdpInput* input, uint32 flags);
typedef void (*pcKeyboardEvent)(rdpInput* input, uint16 flags, uint16 code);
typedef void (*pcUnicodeKeyboardEvent)(rdpInput* input, uint16 code);
typedef void (*pcMouseEvent)(rdpInput* input, uint16 flags, uint16 x, uint16 y);
typedef void (*pcExtendedMouseEvent)(rdpInput* input, uint16 flags, uint16 x, uint16 y);
struct rdp_input
{
struct rdp_rdp* rdp;
pcSynchronizeEvent SynchronizeEvent;
pcKeyboardEvent KeyboardEvent;
pcUnicodeKeyboardEvent UnicodeKeyboardEvent;
pcMouseEvent MouseEvent;
pcExtendedMouseEvent ExtendedMouseEvent;
};
void input_send_synchronize_event(rdpInput* input, uint32 flags);
void input_send_keyboard_event(rdpInput* input, uint16 flags, uint16 code);
void input_send_unicode_keyboard_event(rdpInput* input, uint16 code);
void input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
rdpInput* input_new(rdpRdp* rdp);
void input_free(rdpInput* input);
#endif /* __INPUT_H */

View File

@ -82,7 +82,7 @@ void rdp_read_bitmap_data(STREAM* s, BITMAP_DATA* bitmap_data)
stream_get_mark(s, srcData);
stream_seek(s, bitmap_data->length);
bitmap_data->data = (uint8*) xmalloc(dstSize);
bitmap_data->data = (uint8*) xzalloc(dstSize);
//printf("bytesPerPixel:%d, width:%d, height:%d dstSize:%d flags:0x%04X\n",
// bytesPerPixel, bitmap_data->width, bitmap_data->height, dstSize, bitmap_data->flags);
@ -100,7 +100,7 @@ void rdp_read_bitmap_update(rdpRdp* rdp, STREAM* s, BITMAP_UPDATE* bitmap_update
stream_read_uint16(s, bitmap_update->number); /* numberRectangles (2 bytes) */
bitmap_update->bitmaps = (BITMAP_DATA*) xmalloc(sizeof(BITMAP_DATA) * bitmap_update->number);
bitmap_update->bitmaps = (BITMAP_DATA*) xzalloc(sizeof(BITMAP_DATA) * bitmap_update->number);
/* rectangles */
for (i = 0; i < bitmap_update->number; i++)