Coverage Report

Created: 2025-08-24 06:43

/src/mosquitto/src/send_unsuback.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
Copyright (c) 2009-2021 Roger Light <roger@atchoo.org>
3
4
All rights reserved. This program and the accompanying materials
5
are made available under the terms of the Eclipse Public License 2.0
6
and Eclipse Distribution License v1.0 which accompany this distribution.
7
8
The Eclipse Public License is available at
9
   https://www.eclipse.org/legal/epl-2.0/
10
and the Eclipse Distribution License is available at
11
  http://www.eclipse.org/org/documents/edl-v10.php.
12
13
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
14
15
Contributors:
16
   Roger Light - initial implementation and documentation.
17
*/
18
19
#include "config.h"
20
21
#include <assert.h>
22
23
#include "mosquitto_broker_internal.h"
24
#include "mosquitto/mqtt_protocol.h"
25
#include "packet_mosq.h"
26
#include "property_mosq.h"
27
#include "sys_tree.h"
28
29
30
int send__unsuback(struct mosquitto *mosq, uint16_t mid, int reason_code_count, uint8_t *reason_codes, const mosquitto_property *properties)
31
476
{
32
476
  struct mosquitto__packet *packet = NULL;
33
476
  int rc;
34
476
  uint32_t remaining_length;
35
36
476
  assert(mosq);
37
38
476
  remaining_length = 2;
39
476
  if(mosq->protocol == mosq_p_mqtt5){
40
123
    remaining_length += mosquitto_property_get_remaining_length(properties);
41
123
    remaining_length += (uint32_t)reason_code_count;
42
123
  }
43
44
476
  rc = packet__alloc(&packet, CMD_UNSUBACK, remaining_length);
45
476
  if(rc){
46
0
    return rc;
47
0
  }
48
49
476
  packet__write_uint16(packet, mid);
50
51
476
  if(mosq->protocol == mosq_p_mqtt5){
52
123
    property__write_all(packet, properties, true);
53
123
    packet__write_bytes(packet, reason_codes, (uint32_t)reason_code_count);
54
123
  }
55
56
476
  metrics__int_inc(mosq_counter_mqtt_unsuback_sent, 1);
57
476
  return packet__queue(mosq, packet);
58
476
}