libfreerdp-core: TPKT encoding/decoding

This commit is contained in:
Marc-André Moreau 2011-07-02 14:40:03 -04:00
parent fd2d804578
commit 071516187e
5 changed files with 144 additions and 9 deletions

View File

@ -47,4 +47,4 @@ add_subdirectory(libfreerdp-utils)
add_subdirectory(libfreerdp-kbd)
add_subdirectory(libfreerdp-gdi)
#add_subdirectory(libfreerdp-core)
add_subdirectory(libfreerdp-core)

View File

@ -23,13 +23,13 @@
#include <freerdp/types/base.h>
typedef struct _STREAM STREAM;
struct _STREAM
{
uint8 * buffer;
uint8 * ptr;
uint8 * buffer;
int capacity;
};
typedef struct _STREAM STREAM;
STREAM *
stream_new(int capacity);
@ -88,5 +88,27 @@ stream_extend(STREAM * stream);
*_s->ptr++ = ((_v) >> 48) & 0xFF; \
*_s->ptr++ = ((_v) >> 56) & 0xFF; } while (0)
#define stream_peek_uint8(_s, _v) do { _v = *_s->ptr; } while (0)
#define stream_peek_uint16(_s, _v) do { _v = \
(uint16)(*_s->ptr) + \
(((uint16)(*(_s->ptr + 1))) << 8); \
} while (0)
#define stream_peek_uint32(_s, _v) do { _v = \
(uint32)(*_s->ptr) + \
(((uint32)(*(_s->ptr + 1))) << 8) + \
(((uint32)(*(_s->ptr + 2))) << 16) + \
(((uint32)(*(_s->ptr + 3))) << 24); \
} while (0)
#define stream_peek_uint64(_s, _v) do { _v = \
(uint64)(*_s->ptr) + \
(((uint64)(*(_s->ptr + 1))) << 8) + \
(((uint64)(*(_s->ptr + 2))) << 16) + \
(((uint64)(*(_s->ptr + 3))) << 24) + \
(((uint64)(*(_s->ptr + 4))) << 32) + \
(((uint64)(*(_s->ptr + 5))) << 40) + \
(((uint64)(*(_s->ptr + 6))) << 48) + \
(((uint64)(*(_s->ptr + 7))) << 56); \
} while (0)
#endif /* __STREAM_UTILS_H */

View File

@ -24,12 +24,14 @@ add_definitions(-DL_ENDIAN=1)
add_definitions(-DEXT_PATH="/usr/lib/freerdp/extensions")
set(LIBFREERDP_CORE_SRCS
nego.c
nego.h
credssp.c
credssp.h
ntlmssp.c
ntlmssp.h
# nego.c
# nego.h
# credssp.c
# credssp.h
# ntlmssp.c
# ntlmssp.h
tpkt.c
tpkt.h
)
add_library(freerdp-core SHARED ${LIBFREERDP_CORE_SRCS})

80
libfreerdp-core/tpkt.c Normal file
View File

@ -0,0 +1,80 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* TPKT Headers
*
* 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 "tpkt.h"
/**
* TPKT headers are defined in:
*
* http://tools.ietf.org/html/rfc1006/
* RFC 1006 - ISO Transport Service on top of the TCP
*
* http://www.itu.int/rec/T-REC-T.123/
* ITU-T T.123 (01/2007) - Network-specific data protocol stacks for multimedia conferencing
*
* TPKT Header
* ____________________ byte
* | |
* | 3 (version) | 1
* |____________________|
* | |
* | Reserved | 2
* |____________________|
* | |
* | Length (MSB) | 3
* |____________________|
* | |
* | Length (LSB) | 4
* |____________________|
* | |
* | TPDU | 5 - ?
* ....
*/
#include <freerdp/utils/stream.h>
int
tpkt_read_header(STREAM* s)
{
uint8 version;
uint16 length;
stream_peek_uint8(s, version);
if (version == 3)
{
stream_seek(s, 2);
stream_read_uint16(s, length);
}
else
{
/* not a TPKT header */
length = -1;
}
return length;
}
void
tpkt_write_header(STREAM* s, int length)
{
stream_write_uint8(s, 3); /* version */
stream_write_uint8(s, 8); /* reserved */
stream_write_uint16(s, length); /* length */
}

31
libfreerdp-core/tpkt.h Normal file
View File

@ -0,0 +1,31 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* TPKT Headers
*
* 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 __TPKT_H
#define __TPKT_H
#include <freerdp/utils/stream.h>
int
tpkt_read_header(STREAM* s);
void
tpkt_write_header(STREAM* s, int length);
#endif /* __TPKT_H */