Coverage Report

Created: 2024-05-20 06:11

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