34 |
|
|
35 |
static int sock; |
static int sock; |
36 |
static struct stream in; |
static struct stream in; |
37 |
|
#ifndef WITH_SCARD |
38 |
static struct stream out; |
static struct stream out; |
39 |
|
#endif |
40 |
int g_tcp_port_rdp = TCP_PORT_RDP; |
int g_tcp_port_rdp = TCP_PORT_RDP; |
41 |
|
|
42 |
/* Initialise TCP transport data packet */ |
/* Initialise TCP transport data packet */ |
43 |
STREAM |
STREAM |
44 |
tcp_init(uint32 maxlen) |
tcp_init(uint32 maxlen) |
45 |
{ |
{ |
46 |
if (maxlen > out.size) |
STREAM result = NULL; |
|
{ |
|
|
out.data = (uint8 *) xrealloc(out.data, maxlen); |
|
|
out.size = maxlen; |
|
|
} |
|
47 |
|
|
48 |
out.p = out.data; |
#ifdef WITH_SCARD |
49 |
out.end = out.data + out.size; |
scard_tcp_lock(); |
50 |
return &out; |
result = scard_tcp_init(); |
51 |
|
#else |
52 |
|
result = &out; |
53 |
|
#endif |
54 |
|
|
55 |
|
if (maxlen > result->size) |
56 |
|
{ |
57 |
|
result->data = (uint8 *) xrealloc(result->data, maxlen); |
58 |
|
result->size = maxlen; |
59 |
|
} |
60 |
|
|
61 |
|
result->p = result->data; |
62 |
|
result->end = result->data + result->size; |
63 |
|
#ifdef WITH_SCARD |
64 |
|
scard_tcp_unlock(); |
65 |
|
#endif |
66 |
|
return result; |
67 |
} |
} |
68 |
|
|
69 |
/* Send TCP transport data packet */ |
/* Send TCP transport data packet */ |
73 |
int length = s->end - s->data; |
int length = s->end - s->data; |
74 |
int sent, total = 0; |
int sent, total = 0; |
75 |
|
|
76 |
|
#ifdef WITH_SCARD |
77 |
|
scard_tcp_lock(); |
78 |
|
#endif |
79 |
while (total < length) |
while (total < length) |
80 |
{ |
{ |
81 |
sent = send(sock, s->data + total, length - total, 0); |
sent = send(sock, s->data + total, length - total, 0); |
87 |
|
|
88 |
total += sent; |
total += sent; |
89 |
} |
} |
90 |
|
#ifdef WITH_SCARD |
91 |
|
scard_tcp_unlock(); |
92 |
|
#endif |
93 |
} |
} |
94 |
|
|
95 |
/* Receive a message on the TCP layer */ |
/* Receive a message on the TCP layer */ |
234 |
in.size = 4096; |
in.size = 4096; |
235 |
in.data = (uint8 *) xmalloc(in.size); |
in.data = (uint8 *) xmalloc(in.size); |
236 |
|
|
237 |
|
#ifdef WITH_SCARD |
238 |
|
scard_tcp_connect(); |
239 |
|
#else |
240 |
out.size = 4096; |
out.size = 4096; |
241 |
out.data = (uint8 *) xmalloc(out.size); |
out.data = (uint8 *) xmalloc(out.size); |
242 |
|
#endif |
243 |
|
|
244 |
return True; |
return True; |
245 |
} |
} |
287 |
in.rdp_hdr = NULL; |
in.rdp_hdr = NULL; |
288 |
in.channel_hdr = NULL; |
in.channel_hdr = NULL; |
289 |
|
|
290 |
/* Clear the outgoing stream */ |
/* Clear the outgoing stream(s) */ |
291 |
|
#ifdef WITH_SCARD |
292 |
|
scard_tcp_reset_state(); |
293 |
|
#else |
294 |
if (out.data != NULL) |
if (out.data != NULL) |
295 |
xfree(out.data); |
xfree(out.data); |
296 |
out.p = NULL; |
out.p = NULL; |
302 |
out.sec_hdr = NULL; |
out.sec_hdr = NULL; |
303 |
out.rdp_hdr = NULL; |
out.rdp_hdr = NULL; |
304 |
out.channel_hdr = NULL; |
out.channel_hdr = NULL; |
305 |
|
#endif |
306 |
} |
} |