/src/FreeRDP/libfreerdp/core/heartbeat.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * Heartbeat PDUs |
4 | | * |
5 | | * Copyright 2014 Dell Software <Mike.McDonald@software.dell.com> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #include <freerdp/config.h> |
21 | | |
22 | | #define WITH_DEBUG_HEARTBEAT |
23 | | |
24 | | #include "heartbeat.h" |
25 | | |
26 | | state_run_t rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s) |
27 | 13.2k | { |
28 | 13.2k | BYTE period = 0; |
29 | 13.2k | BYTE count1 = 0; |
30 | 13.2k | BYTE count2 = 0; |
31 | 13.2k | BOOL rc = 0; |
32 | | |
33 | 13.2k | WINPR_ASSERT(rdp); |
34 | 13.2k | WINPR_ASSERT(rdp->context); |
35 | 13.2k | WINPR_ASSERT(s); |
36 | | |
37 | 13.2k | if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 4)) |
38 | 6.33k | return STATE_RUN_FAILED; |
39 | | |
40 | 6.93k | Stream_Seek_UINT8(s); /* reserved (1 byte) */ |
41 | 6.93k | Stream_Read_UINT8(s, period); /* period (1 byte) */ |
42 | 6.93k | Stream_Read_UINT8(s, count1); /* count1 (1 byte) */ |
43 | 6.93k | Stream_Read_UINT8(s, count2); /* count2 (1 byte) */ |
44 | | |
45 | 6.93k | WLog_DBG(HEARTBEAT_TAG, |
46 | 6.93k | "received Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "", |
47 | 6.93k | period, count1, count2); |
48 | | |
49 | 6.93k | rc = IFCALLRESULT(TRUE, rdp->heartbeat->ServerHeartbeat, rdp->context->instance, period, count1, |
50 | 6.93k | count2); |
51 | 6.93k | if (!rc) |
52 | 0 | { |
53 | 0 | WLog_ERR(HEARTBEAT_TAG, "heartbeat->ServerHeartbeat callback failed!"); |
54 | 0 | return STATE_RUN_FAILED; |
55 | 0 | } |
56 | | |
57 | 6.93k | return STATE_RUN_SUCCESS; |
58 | 6.93k | } |
59 | | |
60 | | BOOL freerdp_heartbeat_send_heartbeat_pdu(freerdp_peer* peer, BYTE period, BYTE count1, BYTE count2) |
61 | 0 | { |
62 | 0 | rdpRdp* rdp = peer->context->rdp; |
63 | 0 | wStream* s = rdp_message_channel_pdu_init(rdp); |
64 | |
|
65 | 0 | if (!s) |
66 | 0 | return FALSE; |
67 | | |
68 | 0 | Stream_Seek_UINT8(s); /* reserved (1 byte) */ |
69 | 0 | Stream_Write_UINT8(s, period); /* period (1 byte) */ |
70 | 0 | Stream_Write_UINT8(s, count1); /* count1 (1 byte) */ |
71 | 0 | Stream_Write_UINT8(s, count2); /* count2 (1 byte) */ |
72 | |
|
73 | 0 | WLog_DBG(HEARTBEAT_TAG, |
74 | 0 | "sending Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "", |
75 | 0 | period, count1, count2); |
76 | |
|
77 | 0 | if (!rdp_send_message_channel_pdu(rdp, s, SEC_HEARTBEAT)) |
78 | 0 | return FALSE; |
79 | | |
80 | 0 | return TRUE; |
81 | 0 | } |
82 | | |
83 | | rdpHeartbeat* heartbeat_new(void) |
84 | 13.2k | { |
85 | 13.2k | rdpHeartbeat* heartbeat = (rdpHeartbeat*)calloc(1, sizeof(rdpHeartbeat)); |
86 | | |
87 | 13.2k | if (heartbeat) |
88 | 13.2k | { |
89 | 13.2k | } |
90 | | |
91 | 13.2k | return heartbeat; |
92 | 13.2k | } |
93 | | |
94 | | void heartbeat_free(rdpHeartbeat* heartbeat) |
95 | 13.2k | { |
96 | 13.2k | free(heartbeat); |
97 | 13.2k | } |