Coverage Report

Created: 2025-07-01 06:46

/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
#include "heartbeat.h"
23
24
state_run_t rdp_recv_heartbeat_packet(rdpRdp* rdp, wStream* s)
25
0
{
26
0
  BYTE period = 0;
27
0
  BYTE count1 = 0;
28
0
  BYTE count2 = 0;
29
0
  BOOL rc = 0;
30
31
0
  WINPR_ASSERT(rdp);
32
0
  WINPR_ASSERT(rdp->context);
33
0
  WINPR_ASSERT(s);
34
35
0
  if (!Stream_CheckAndLogRequiredLength(AUTODETECT_TAG, s, 4))
36
0
    return STATE_RUN_FAILED;
37
38
0
  Stream_Seek_UINT8(s);           /* reserved (1 byte) */
39
0
  Stream_Read_UINT8(s, period);   /* period (1 byte) */
40
0
  Stream_Read_UINT8(s, count1);   /* count1 (1 byte) */
41
0
  Stream_Read_UINT8(s, count2);   /* count2 (1 byte) */
42
43
0
  WLog_VRB(HEARTBEAT_TAG,
44
0
           "received Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "",
45
0
           period, count1, count2);
46
47
0
  rc = IFCALLRESULT(TRUE, rdp->heartbeat->ServerHeartbeat, rdp->context->instance, period, count1,
48
0
                    count2);
49
0
  if (!rc)
50
0
  {
51
0
    WLog_ERR(HEARTBEAT_TAG, "heartbeat->ServerHeartbeat callback failed!");
52
0
    return STATE_RUN_FAILED;
53
0
  }
54
55
0
  return STATE_RUN_SUCCESS;
56
0
}
57
58
BOOL freerdp_heartbeat_send_heartbeat_pdu(freerdp_peer* peer, BYTE period, BYTE count1, BYTE count2)
59
0
{
60
0
  rdpRdp* rdp = peer->context->rdp;
61
0
  UINT16 sec_flags = 0;
62
0
  wStream* s = rdp_message_channel_pdu_init(rdp, &sec_flags);
63
64
0
  if (!s)
65
0
    return FALSE;
66
67
0
  Stream_Seek_UINT8(s);          /* reserved (1 byte) */
68
0
  Stream_Write_UINT8(s, period); /* period (1 byte) */
69
0
  Stream_Write_UINT8(s, count1); /* count1 (1 byte) */
70
0
  Stream_Write_UINT8(s, count2); /* count2 (1 byte) */
71
72
0
  WLog_DBG(HEARTBEAT_TAG,
73
0
           "sending Heartbeat PDU -> period=%" PRIu8 ", count1=%" PRIu8 ", count2=%" PRIu8 "",
74
0
           period, count1, count2);
75
76
0
  if (!rdp_send_message_channel_pdu(rdp, s, sec_flags | SEC_HEARTBEAT))
77
0
    return FALSE;
78
79
0
  return TRUE;
80
0
}
81
82
rdpHeartbeat* heartbeat_new(void)
83
0
{
84
0
  rdpHeartbeat* heartbeat = (rdpHeartbeat*)calloc(1, sizeof(rdpHeartbeat));
85
86
0
  if (heartbeat)
87
0
  {
88
0
  }
89
90
0
  return heartbeat;
91
0
}
92
93
void heartbeat_free(rdpHeartbeat* heartbeat)
94
0
{
95
0
  free(heartbeat);
96
0
}