Skip to content

Commit

Permalink
libfreerdp-core: cleanup of tcp.c, secure.c, nego.c
Browse files Browse the repository at this point in the history
  • Loading branch information
awakecoding committed Jun 29, 2011
1 parent 2b95558 commit bb5f40c
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 85 deletions.
20 changes: 6 additions & 14 deletions libfreerdp-core/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ x224_send_dst_src_class(rdpIso * iso, uint8 code)
{
STREAM s;

s = tcp_init(iso->tcp, 11);
s = network_stream_init(iso->net, 11);

tpkt_output_header(s, 11);

Expand Down Expand Up @@ -104,7 +104,7 @@ x224_send_connection_request(rdpIso * iso)
length += 8;

/* FIXME: Use x224_send_dst_src_class */
s = tcp_init(iso->tcp, length);
s = network_stream_init(iso->net, length);

tpkt_output_header(s, length);

Expand Down Expand Up @@ -268,7 +268,7 @@ STREAM
iso_init(rdpIso * iso, int length)
{
STREAM s;
s = tcp_init(iso->tcp, length + 7);
s = network_stream_init(iso->net, length + 7);
s_push_layer(s, iso_hdr, 7);
return s;
}
Expand All @@ -278,7 +278,7 @@ STREAM
iso_fp_init(rdpIso * iso, int length)
{
STREAM s;
s = tcp_init(iso->tcp, length + 3);
s = network_stream_init(iso->net, length + 3);
s_push_layer(s, iso_hdr, 3);
return s;
}
Expand Down Expand Up @@ -399,11 +399,7 @@ void
iso_disconnect(rdpIso * iso)
{
x224_send_dst_src_class(iso, X224_TPDU_DISCONNECT_REQUEST);
#ifndef DISABLE_TLS
if (iso->net->tls)
tls_disconnect(iso->net->tls);
#endif
tcp_disconnect(iso->tcp);
network_disconnect(iso->net);
}

rdpIso *
Expand All @@ -418,8 +414,7 @@ iso_new(struct rdp_network * net)
memset(self, 0, sizeof(rdpIso));
self->net = net;
self->mcs = net->mcs;
self->tcp = tcp_new(self);
self->nego = nego_new(self);
self->nego = net->nego;
}

return self;
Expand All @@ -430,9 +425,6 @@ iso_free(rdpIso * iso)
{
if (iso != NULL)
{
tcp_free(iso->tcp);
if (iso->nego != NULL)
nego_free(iso->nego);
xfree(iso);
}
}
1 change: 0 additions & 1 deletion libfreerdp-core/iso.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ struct rdp_iso
{
char* cookie;
struct _NEGO * nego;
struct rdp_tcp * tcp;
struct rdp_mcs * mcs;
struct rdp_network * net;
};
Expand Down
20 changes: 10 additions & 10 deletions libfreerdp-core/nego.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int nego_tcp_connect(NEGO *nego)
{
if (nego->tcp_connected == 0)
{
if (tcp_connect(nego->iso->tcp, nego->hostname, nego->port) == False)
if (tcp_connect(nego->net->tcp, nego->hostname, nego->port) == False)
{
nego->tcp_connected = 0;
return 0;
Expand All @@ -93,7 +93,7 @@ int nego_tcp_connect(NEGO *nego)
int nego_tcp_disconnect(NEGO *nego)
{
if (nego->tcp_connected)
tcp_disconnect(nego->iso->tcp);
tcp_disconnect(nego->net->tcp);

nego->tcp_connected = 0;
return 1;
Expand All @@ -110,8 +110,8 @@ void nego_attempt_nla(NEGO *nego)
nego->requested_protocols = PROTOCOL_NLA | PROTOCOL_TLS;

nego_tcp_connect(nego);
x224_send_connection_request(nego->iso);
tpkt_recv(nego->iso, &code, NULL);
x224_send_connection_request(nego->net->iso);
tpkt_recv(nego->net->iso, &code, NULL);

if (nego->state != NEGO_STATE_FINAL)
{
Expand All @@ -137,8 +137,8 @@ void nego_attempt_tls(NEGO *nego)
nego->requested_protocols = PROTOCOL_TLS;

nego_tcp_connect(nego);
x224_send_connection_request(nego->iso);
tpkt_recv(nego->iso, &code, NULL);
x224_send_connection_request(nego->net->iso);
tpkt_recv(nego->net->iso, &code, NULL);

if (nego->state != NEGO_STATE_FINAL)
{
Expand All @@ -162,9 +162,9 @@ void nego_attempt_rdp(NEGO *nego)
nego->requested_protocols = PROTOCOL_RDP;

nego_tcp_connect(nego);
x224_send_connection_request(nego->iso);
x224_send_connection_request(nego->net->iso);

if (tpkt_recv(nego->iso, &code, NULL) == NULL)
if (tpkt_recv(nego->net->iso, &code, NULL) == NULL)
nego->state = NEGO_STATE_FAIL;
else
nego->state = NEGO_STATE_FINAL;
Expand Down Expand Up @@ -278,14 +278,14 @@ void nego_process_negotiation_failure(NEGO *nego, STREAM s)
* @return
*/

NEGO* nego_new(struct rdp_iso * iso)
NEGO* nego_new(struct rdp_network * net)
{
NEGO *nego = (NEGO*) xmalloc(sizeof(NEGO));

if (nego != NULL)
{
memset(nego, '\0', sizeof(NEGO));
nego->iso = iso;
nego->net = net;
nego_init(nego);
}

Expand Down
6 changes: 3 additions & 3 deletions libfreerdp-core/nego.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "frdp.h"
#include "stream.h"
#include "iso.h"
#include "network.h"

enum _NEGO_STATE
{
Expand All @@ -41,7 +41,7 @@ struct _NEGO
char *hostname;
NEGO_STATE state;
int tcp_connected;
struct rdp_iso * iso;
struct rdp_network * net;
uint32 selected_protocol;
uint32 requested_protocols;
uint8 enabled_protocols[3];
Expand All @@ -60,7 +60,7 @@ void nego_recv(NEGO *nego, STREAM s);
void nego_process_negotiation_response(NEGO *nego, STREAM s);
void nego_process_negotiation_failure(NEGO *nego, STREAM s);

NEGO* nego_new(rdpIso * iso);
NEGO* nego_new(struct rdp_network * net);
void nego_init(NEGO *nego);
void nego_free(NEGO *nego);

Expand Down
51 changes: 51 additions & 0 deletions libfreerdp-core/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@

#include "network.h"

/* Initialize and return STREAM.
* The stream will have room for at least min_size.
* The tcp layers out stream will be used. */

STREAM
network_stream_init(rdpNetwork * net, uint32 min_size)
{
STREAM result = &(net->out);

if (min_size > result->size)
{
result->data = (uint8 *) xrealloc(result->data, min_size);
result->size = min_size;
}

result->p = result->data;
result->end = result->data + result->size;

return result;
}

#ifndef DISABLE_TLS

/* verify SSL/TLS connection integrity. 2 checks are carried out. First make sure that the
Expand Down Expand Up @@ -176,6 +197,16 @@ network_connect(rdpNetwork * net, char* server, char* username, int port)
return 0;
}

void
network_disconnect(rdpNetwork * net)
{
#ifndef DISABLE_TLS
if (net->tls)
tls_disconnect(net->tls);
#endif
tcp_disconnect(net->tcp);
}

void
network_send(rdpNetwork * net, STREAM s)
{
Expand Down Expand Up @@ -260,9 +291,13 @@ network_new(rdpRdp * rdp)
{
memset(self, 0, sizeof(rdpNetwork));
self->rdp = rdp;
self->sec = rdp->sec;
self->mcs = mcs_new(self);
self->tcp = tcp_new(self);
self->nego = nego_new(self);
self->iso = iso_new(self);
self->license = license_new(self);
self->sec->net = self;

self->in.size = 4096;
self->in.data = (uint8 *) xmalloc(self->in.size);
Expand All @@ -281,6 +316,22 @@ network_free(rdpNetwork * net)
{
xfree(net->in.data);
xfree(net->out.data);

if (net->tcp != NULL)
tcp_free(net->tcp);

if (net->iso != NULL)
iso_free(net->iso);

if (net->mcs != NULL)
mcs_free(net->mcs);

if (net->nego != NULL)
nego_free(net->nego);

if (net->license != NULL)
license_free(net->license);

xfree(net);
}
}
7 changes: 5 additions & 2 deletions libfreerdp-core/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct rdp_network
char* username;
struct stream in;
struct stream out;
struct _NEGO * nego;
struct rdp_rdp * rdp;
struct rdp_tcp * tcp;
struct rdp_sec * sec;
Expand All @@ -51,18 +52,20 @@ struct rdp_network
};
typedef struct rdp_network rdpNetwork;

STREAM
network_stream_init(rdpNetwork * net, uint32 min_size);
RD_BOOL
network_connect(rdpNetwork * net, char* server, char* username, int port);
void
network_disconnect(rdpNetwork * net);

void
network_send(rdpNetwork * net, STREAM s);

STREAM
network_recv(rdpNetwork * net, STREAM s, uint32 length);

rdpNetwork*
network_new(rdpRdp * rdp);

void
network_free(rdpNetwork * net);

Expand Down
6 changes: 1 addition & 5 deletions libfreerdp-core/rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,16 +1750,12 @@ rdp_new(struct rdp_set *settings, struct rdp_inst *inst)
self->buffer_size = 2048;
self->buffer = xmalloc(self->buffer_size);
memset(self->buffer, 0, self->buffer_size);
self->net = network_new(self);
self->sec = sec_new(self);
self->net = network_new(self);
self->orders = orders_new(self);
self->pcache = pcache_new(self);
self->cache = cache_new(self);
self->ext = ext_new(self);

self->net->rdp = self;
self->net->sec = self->sec;
self->net->tcp = self->net->iso->tcp;
}
return self;
}
Expand Down
Loading

0 comments on commit bb5f40c

Please sign in to comment.