2014-05-07 22:27:00 +00:00
|
|
|
/*
|
2015-04-19 21:10:59 +00:00
|
|
|
Copyright (c) 2009-2015 Roger Light <roger@atchoo.org>
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
2016-03-06 22:30:17 +00:00
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
The Eclipse Public License is available at
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
and the Eclipse Distribution License is available at
|
|
|
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
2016-03-06 22:30:17 +00:00
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
Contributors:
|
|
|
|
Roger Light - initial implementation and documentation.
|
|
|
|
*/
|
|
|
|
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "config.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "mosquitto_broker.h"
|
|
|
|
#include "mqtt3_protocol.h"
|
|
|
|
#include "memory_mosq.h"
|
|
|
|
#include "packet_mosq.h"
|
|
|
|
#include "util_mosq.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
|
2015-05-16 14:24:24 +00:00
|
|
|
int send__suback(struct mosquitto *context, uint16_t mid, uint32_t payloadlen, const void *payload)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2015-04-19 21:10:59 +00:00
|
|
|
struct mosquitto__packet *packet = NULL;
|
2014-05-07 22:27:00 +00:00
|
|
|
int rc;
|
|
|
|
|
2015-05-18 07:53:21 +00:00
|
|
|
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending SUBACK to %s", context->id);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2015-04-19 21:10:59 +00:00
|
|
|
packet = mosquitto__calloc(1, sizeof(struct mosquitto__packet));
|
2014-05-07 22:27:00 +00:00
|
|
|
if(!packet) return MOSQ_ERR_NOMEM;
|
|
|
|
|
|
|
|
packet->command = SUBACK;
|
|
|
|
packet->remaining_length = 2+payloadlen;
|
2015-05-16 13:16:40 +00:00
|
|
|
rc = packet__alloc(packet);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(rc){
|
2015-04-19 21:10:59 +00:00
|
|
|
mosquitto__free(packet);
|
2014-05-07 22:27:00 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2015-05-16 13:16:40 +00:00
|
|
|
packet__write_uint16(packet, mid);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(payloadlen){
|
2015-05-16 13:16:40 +00:00
|
|
|
packet__write_bytes(packet, payload, payloadlen);
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 13:16:40 +00:00
|
|
|
return packet__queue(context, packet);
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|