Skip to content

Commit e98b4b2

Browse files
committed
libfreerdp-core: rts code style cleanup
1 parent bd6861c commit e98b4b2

File tree

6 files changed

+42
-858
lines changed

6 files changed

+42
-858
lines changed

dbg.txt

-562
This file was deleted.

libfreerdp/core/rpc.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ void ntlm_client_uninit(rdpNtlm* ntlm)
441441

442442
rdpNtlm* ntlm_new()
443443
{
444-
rdpNtlm* ntlm = xnew(rdpNtlm);
444+
rdpNtlm* ntlm = (rdpNtlm*) malloc(sizeof(rdpNtlm));
445445

446446
if (ntlm != NULL)
447447
{
448-
448+
ZeroMemory(ntlm, sizeof(rdpNtlm));
449449
}
450450

451451
return ntlm;
@@ -1021,8 +1021,6 @@ int rpc_recv_pdu(rdpRpc* rpc)
10211021
return header->frag_length;
10221022
}
10231023

1024-
/* TODO: verify, there seems to be trailing junk added */
1025-
10261024
int rpc_tsg_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
10271025
{
10281026
int status;
@@ -1196,13 +1194,16 @@ void rpc_client_virtual_connection_init(rdpRpc* rpc, RpcVirtualConnection* virtu
11961194

11971195
RpcVirtualConnection* rpc_client_virtual_connection_new(rdpRpc* rpc)
11981196
{
1199-
RpcVirtualConnection* virtual_connection = xnew(RpcVirtualConnection);
1197+
RpcVirtualConnection* virtual_connection = (RpcVirtualConnection*) malloc(sizeof(RpcVirtualConnection));
12001198

12011199
if (virtual_connection != NULL)
12021200
{
1201+
ZeroMemory(virtual_connection, sizeof(RpcVirtualConnection));
12031202
virtual_connection->State = VIRTUAL_CONNECTION_STATE_INITIAL;
1204-
virtual_connection->DefaultInChannel = xnew(RpcInChannel);
1205-
virtual_connection->DefaultOutChannel = xnew(RpcOutChannel);
1203+
virtual_connection->DefaultInChannel = (RpcInChannel*) malloc(sizeof(RpcInChannel));
1204+
virtual_connection->DefaultOutChannel = (RpcOutChannel*) malloc(sizeof(RpcOutChannel));
1205+
ZeroMemory(virtual_connection->DefaultInChannel, sizeof(RpcInChannel));
1206+
ZeroMemory(virtual_connection->DefaultOutChannel, sizeof(RpcOutChannel));
12061207
rpc_client_virtual_connection_init(rpc, virtual_connection);
12071208
}
12081209

@@ -1221,10 +1222,11 @@ rdpNtlmHttp* ntlm_http_new()
12211222
{
12221223
rdpNtlmHttp* ntlm_http;
12231224

1224-
ntlm_http = xnew(rdpNtlmHttp);
1225+
ntlm_http = (rdpNtlmHttp*) malloc(sizeof(rdpNtlmHttp));
12251226

12261227
if (ntlm_http != NULL)
12271228
{
1229+
ZeroMemory(ntlm_http, sizeof(rdpNtlmHttp));
12281230
ntlm_http->ntlm = ntlm_new();
12291231
ntlm_http->context = http_context_new();
12301232
}
@@ -1270,10 +1272,12 @@ void ntlm_http_free(rdpNtlmHttp* ntlm_http)
12701272

12711273
rdpRpc* rpc_new(rdpTransport* transport)
12721274
{
1273-
rdpRpc* rpc = (rdpRpc*) xnew(rdpRpc);
1275+
rdpRpc* rpc = (rdpRpc*) malloc(sizeof(rdpRpc));
12741276

12751277
if (rpc != NULL)
12761278
{
1279+
ZeroMemory(rpc, sizeof(rdpRpc));
1280+
12771281
rpc->transport = transport;
12781282
rpc->settings = transport->settings;
12791283

libfreerdp/core/rpc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ BOOL rpc_connect(rdpRpc* rpc);
581581
BOOL rpc_ntlm_http_out_connect(rdpRpc* rpc);
582582
BOOL rpc_ntlm_http_in_connect(rdpRpc* rpc);
583583

584-
void rpc_pdu_header_read(STREAM* s, RPC_PDU_HEADER* header);
584+
void rpc_pdu_header_init(rdpRpc* rpc, RPC_PDU_HEADER* header);
585585

586586
UINT32 rpc_offset_align(UINT32* offset, UINT32 alignment);
587587
UINT32 rpc_offset_pad(UINT32* offset, UINT32 pad);

libfreerdp/core/rts.c

+28-82
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,14 @@ static const char* const RTS_CMD_STRINGS[] =
127127

128128
#endif
129129

130-
void rts_pdu_header_read(STREAM* s, RTS_PDU_HEADER* header)
131-
{
132-
stream_read_BYTE(s, header->rpc_vers); /* rpc_vers (1 byte) */
133-
stream_read_BYTE(s, header->rpc_vers_minor); /* rpc_vers_minor (1 byte) */
134-
stream_read_BYTE(s, header->ptype); /* PTYPE (1 byte) */
135-
stream_read_BYTE(s, header->pfc_flags); /* pfc_flags (1 byte) */
136-
stream_read_BYTE(s, header->packed_drep[0]); /* packet_drep[0] (1 byte) */
137-
stream_read_BYTE(s, header->packed_drep[1]); /* packet_drep[1] (1 byte) */
138-
stream_read_BYTE(s, header->packed_drep[2]); /* packet_drep[2] (1 byte) */
139-
stream_read_BYTE(s, header->packed_drep[3]); /* packet_drep[3] (1 byte) */
140-
stream_read_UINT16(s, header->frag_length); /* frag_length (2 bytes) */
141-
stream_read_UINT16(s, header->auth_length); /* auth_length (2 bytes) */
142-
stream_read_UINT32(s, header->call_id); /* call_id (4 bytes) */
143-
stream_read_UINT16(s, header->flags); /* flags (2 bytes) */
144-
stream_read_UINT16(s, header->numberOfCommands); /* numberOfCommands (2 bytes) */
145-
}
146-
147-
void rts_pdu_header_write(STREAM* s, RTS_PDU_HEADER* header)
148-
{
149-
stream_write_BYTE(s, header->rpc_vers); /* rpc_vers (1 byte) */
150-
stream_write_BYTE(s, header->rpc_vers_minor); /* rpc_vers_minor (1 byte) */
151-
stream_write_BYTE(s, header->ptype); /* PTYPE (1 byte) */
152-
stream_write_BYTE(s, header->pfc_flags); /* pfc_flags (1 byte) */
153-
stream_write_BYTE(s, header->packed_drep[0]); /* packet_drep[0] (1 byte) */
154-
stream_write_BYTE(s, header->packed_drep[1]); /* packet_drep[1] (1 byte) */
155-
stream_write_BYTE(s, header->packed_drep[2]); /* packet_drep[2] (1 byte) */
156-
stream_write_BYTE(s, header->packed_drep[3]); /* packet_drep[3] (1 byte) */
157-
stream_write_UINT16(s, header->frag_length); /* frag_length (2 bytes) */
158-
stream_write_UINT16(s, header->auth_length); /* auth_length (2 bytes) */
159-
stream_write_UINT32(s, header->call_id); /* call_id (4 bytes) */
160-
stream_write_UINT16(s, header->flags); /* flags (2 bytes) */
161-
stream_write_UINT16(s, header->numberOfCommands); /* numberOfCommands (2 bytes) */
130+
void rts_pdu_header_init(rdpRpc* rpc, RTS_PDU_HEADER* header)
131+
{
132+
header->rpc_vers = rpc->rpc_vers;
133+
header->rpc_vers_minor = rpc->rpc_vers_minor;
134+
header->packed_drep[0] = rpc->packed_drep[0];
135+
header->packed_drep[1] = rpc->packed_drep[1];
136+
header->packed_drep[2] = rpc->packed_drep[2];
137+
header->packed_drep[3] = rpc->packed_drep[3];
162138
}
163139

164140
void rts_receive_window_size_command_read(rdpRpc* rpc, STREAM* s)
@@ -370,14 +346,10 @@ BOOL rts_send_CONN_A1_pdu(rdpRpc* rpc)
370346
BYTE* OUTChannelCookie;
371347
BYTE* VirtualConnectionCookie;
372348

373-
header.rpc_vers = 5;
374-
header.rpc_vers_minor = 0;
349+
rts_pdu_header_init(rpc, &header);
350+
375351
header.ptype = PTYPE_RTS;
376352
header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
377-
header.packed_drep[0] = 0x10;
378-
header.packed_drep[1] = 0x00;
379-
header.packed_drep[2] = 0x00;
380-
header.packed_drep[3] = 0x00;
381353
header.frag_length = 76;
382354
header.auth_length = 0;
383355
header.call_id = 0;
@@ -395,7 +367,7 @@ BOOL rts_send_CONN_A1_pdu(rdpRpc* rpc)
395367
OUTChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie);
396368
ReceiveWindowSize = rpc->VirtualConnection->DefaultOutChannel->ReceiveWindow;
397369

398-
rts_pdu_header_write(s, &header); /* RTS Header (20 bytes) */
370+
stream_write(s, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
399371
rts_version_command_write(s); /* Version (8 bytes) */
400372
rts_cookie_command_write(s, VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
401373
rts_cookie_command_write(s, OUTChannelCookie); /* OUTChannelCookie (20 bytes) */
@@ -417,14 +389,10 @@ BOOL rts_send_CONN_B1_pdu(rdpRpc* rpc)
417389
BYTE* AssociationGroupId;
418390
BYTE* VirtualConnectionCookie;
419391

420-
header.rpc_vers = 5;
421-
header.rpc_vers_minor = 0;
392+
rts_pdu_header_init(rpc, &header);
393+
422394
header.ptype = PTYPE_RTS;
423395
header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
424-
header.packed_drep[0] = 0x10;
425-
header.packed_drep[1] = 0x00;
426-
header.packed_drep[2] = 0x00;
427-
header.packed_drep[3] = 0x00;
428396
header.frag_length = 104;
429397
header.auth_length = 0;
430398
header.call_id = 0;
@@ -442,7 +410,7 @@ BOOL rts_send_CONN_B1_pdu(rdpRpc* rpc)
442410
INChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultInChannelCookie);
443411
AssociationGroupId = (BYTE*) &(rpc->VirtualConnection->AssociationGroupId);
444412

445-
rts_pdu_header_write(s, &header); /* RTS Header (20 bytes) */
413+
stream_write(s, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
446414
rts_version_command_write(s); /* Version (8 bytes) */
447415
rts_cookie_command_write(s, VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
448416
rts_cookie_command_write(s, INChannelCookie); /* INChannelCookie (20 bytes) */
@@ -463,14 +431,10 @@ BOOL rts_send_keep_alive_pdu(rdpRpc* rpc)
463431
STREAM* s;
464432
RTS_PDU_HEADER header;
465433

466-
header.rpc_vers = 5;
467-
header.rpc_vers_minor = 0;
434+
rts_pdu_header_init(rpc, &header);
435+
468436
header.ptype = PTYPE_RTS;
469437
header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
470-
header.packed_drep[0] = 0x10;
471-
header.packed_drep[1] = 0x00;
472-
header.packed_drep[2] = 0x00;
473-
header.packed_drep[3] = 0x00;
474438
header.frag_length = 28;
475439
header.auth_length = 0;
476440
header.call_id = 0;
@@ -480,7 +444,7 @@ BOOL rts_send_keep_alive_pdu(rdpRpc* rpc)
480444
DEBUG_RPC("Sending Keep-Alive RTS PDU");
481445

482446
s = stream_new(header.frag_length);
483-
rts_pdu_header_write(s, &header); /* RTS Header (20 bytes) */
447+
stream_write(s, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
484448
rts_client_keepalive_command_write(s, 0x00007530); /* ClientKeepalive (8 bytes) */
485449
stream_seal(s);
486450

@@ -499,14 +463,10 @@ BOOL rts_send_flow_control_ack_pdu(rdpRpc* rpc)
499463
UINT32 AvailableWindow;
500464
BYTE* ChannelCookie;
501465

502-
header.rpc_vers = 5;
503-
header.rpc_vers_minor = 0;
466+
rts_pdu_header_init(rpc, &header);
467+
504468
header.ptype = PTYPE_RTS;
505469
header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
506-
header.packed_drep[0] = 0x10;
507-
header.packed_drep[1] = 0x00;
508-
header.packed_drep[2] = 0x00;
509-
header.packed_drep[3] = 0x00;
510470
header.frag_length = 56;
511471
header.auth_length = 0;
512472
header.call_id = 0;
@@ -520,7 +480,7 @@ BOOL rts_send_flow_control_ack_pdu(rdpRpc* rpc)
520480
ChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie);
521481

522482
s = stream_new(header.frag_length);
523-
rts_pdu_header_write(s, &header); /* RTS Header (20 bytes) */
483+
stream_write(s, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
524484
rts_destination_command_write(s, FDOutProxy); /* Destination Command (8 bytes) */
525485

526486
/* FlowControlAck Command (28 bytes) */
@@ -540,14 +500,10 @@ BOOL rts_send_ping_pdu(rdpRpc* rpc)
540500
STREAM* s;
541501
RTS_PDU_HEADER header;
542502

543-
header.rpc_vers = 5;
544-
header.rpc_vers_minor = 0;
503+
rts_pdu_header_init(rpc, &header);
504+
545505
header.ptype = PTYPE_RTS;
546506
header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG;
547-
header.packed_drep[0] = 0x10;
548-
header.packed_drep[1] = 0x00;
549-
header.packed_drep[2] = 0x00;
550-
header.packed_drep[3] = 0x00;
551507
header.frag_length = 20;
552508
header.auth_length = 0;
553509
header.call_id = 0;
@@ -557,7 +513,7 @@ BOOL rts_send_ping_pdu(rdpRpc* rpc)
557513
DEBUG_RPC("Sending Ping RTS PDU");
558514

559515
s = stream_new(header.frag_length);
560-
rts_pdu_header_write(s, &header); /* RTS Header (20 bytes) */
516+
stream_write(s, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
561517
stream_seal(s);
562518

563519
rpc_in_write(rpc, s->data, s->size);
@@ -669,48 +625,38 @@ int rts_recv_pdu_commands(rdpRpc* rpc, RTS_PDU* rts_pdu)
669625

670626
int rts_recv_pdu(rdpRpc* rpc, RTS_PDU* rts_pdu)
671627
{
672-
STREAM* s;
673628
int status;
674629
int length;
675-
BYTE header_buffer[20];
676630
rdpTls* tls_out = rpc->tls_out;
677631

678632
/* read first 20 bytes to get RTS PDU Header */
679-
status = tls_read(tls_out, (BYTE*) &header_buffer, 20);
633+
status = tls_read(tls_out, (BYTE*) &(rts_pdu->header), 20);
680634

681635
if (status <= 0)
682636
{
683-
printf("rts_recv error\n");
637+
printf("rts_recv_pdu error\n");
684638
return status;
685639
}
686640

687-
s = stream_new(0);
688-
stream_attach(s, header_buffer, 20);
689-
690-
rts_pdu_header_read(s, &(rts_pdu->header));
691-
692-
stream_detach(s);
693-
stream_free(s);
694-
695641
length = rts_pdu->header.frag_length - 20;
696642
rts_pdu->content = (BYTE*) malloc(length);
697643

698644
status = tls_read(tls_out, rts_pdu->content, length);
699645

700646
if (status < 0)
701647
{
702-
printf("rts_recv error\n");
648+
printf("rts_recv_pdu error\n");
703649
return status;
704650
}
705651

706652
if (rts_pdu->header.ptype != PTYPE_RTS)
707653
{
708-
printf("rts_recv error: unexpected ptype:%d\n", rts_pdu->header.ptype);
654+
printf("rts_recv_pdu error: unexpected ptype: %d\n", rts_pdu->header.ptype);
709655
return -1;
710656
}
711657

712658
#ifdef WITH_DEBUG_RTS
713-
printf("rts_recv(): length: %d\n", length);
659+
printf("rts_recv_pdu: length: %d\n", length);
714660
freerdp_hexdump(rts_pdu->content, length);
715661
printf("\n");
716662
#endif

libfreerdp/core/rts.h

-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ typedef struct _rts_pdu RTS_PDU;
116116

117117
BOOL rts_connect(rdpRpc* rpc);
118118

119-
void rts_pdu_header_read(STREAM* s, RTS_PDU_HEADER* header);
120-
void rts_pdu_header_write(STREAM* s, RTS_PDU_HEADER* header);
121-
122119
void rts_receive_window_size_command_read(rdpRpc* rpc, STREAM* s);
123120
void rts_receive_window_size_command_write(STREAM* s, UINT32 ReceiveWindowSize);
124121
void rts_flow_control_ack_command_read(rdpRpc* rpc, STREAM* s);

0 commit comments

Comments
 (0)