2014-05-07 22:27:00 +00:00
|
|
|
/*
|
2018-04-11 14:24:29 +00:00
|
|
|
Copyright (c) 2009-2018 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.
|
|
|
|
*/
|
|
|
|
|
2018-08-16 10:14:51 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "mosquitto.h"
|
|
|
|
#include "logging_mosq.h"
|
|
|
|
#include "memory_mosq.h"
|
2015-05-24 10:52:38 +00:00
|
|
|
#include "messages_mosq.h"
|
2018-10-25 11:03:22 +00:00
|
|
|
#include "mqtt_protocol.h"
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "net_mosq.h"
|
|
|
|
#include "packet_mosq.h"
|
2018-10-25 11:03:22 +00:00
|
|
|
#include "property_mosq.h"
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "read_handle.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2015-05-16 17:43:06 +00:00
|
|
|
int handle__connack(struct mosquitto *mosq)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2018-04-11 13:06:16 +00:00
|
|
|
uint8_t connect_flags;
|
2018-10-25 11:03:22 +00:00
|
|
|
uint8_t reason_code;
|
2014-05-07 22:27:00 +00:00
|
|
|
int rc;
|
2018-10-25 11:03:22 +00:00
|
|
|
struct mqtt5__property *properties = NULL;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
assert(mosq);
|
2018-04-11 13:06:16 +00:00
|
|
|
rc = packet__read_byte(&mosq->in_packet, &connect_flags);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(rc) return rc;
|
2018-10-25 11:03:22 +00:00
|
|
|
rc = packet__read_byte(&mosq->in_packet, &reason_code);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(rc) return rc;
|
2018-10-25 11:03:22 +00:00
|
|
|
|
|
|
|
if(mosq->protocol == mosq_p_mqtt5){
|
2018-10-30 11:00:16 +00:00
|
|
|
rc = property__read_all(CMD_CONNACK, &mosq->in_packet, &properties);
|
2018-10-25 11:03:22 +00:00
|
|
|
if(rc) return rc;
|
2018-10-30 10:11:20 +00:00
|
|
|
mosquitto_property_free_all(&properties);
|
2018-10-25 11:03:22 +00:00
|
|
|
}
|
2018-10-30 10:11:20 +00:00
|
|
|
mosquitto_property_free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
|
2018-10-25 11:03:22 +00:00
|
|
|
|
|
|
|
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK (%d)", mosq->id, reason_code);
|
2014-05-07 22:27:00 +00:00
|
|
|
pthread_mutex_lock(&mosq->callback_mutex);
|
|
|
|
if(mosq->on_connect){
|
|
|
|
mosq->in_callback = true;
|
2018-10-25 11:03:22 +00:00
|
|
|
mosq->on_connect(mosq, mosq->userdata, reason_code);
|
2014-05-07 22:27:00 +00:00
|
|
|
mosq->in_callback = false;
|
|
|
|
}
|
2018-04-11 13:06:16 +00:00
|
|
|
if(mosq->on_connect_with_flags){
|
|
|
|
mosq->in_callback = true;
|
2018-10-25 11:03:22 +00:00
|
|
|
mosq->on_connect_with_flags(mosq, mosq->userdata, reason_code, connect_flags);
|
2018-04-11 13:06:16 +00:00
|
|
|
mosq->in_callback = false;
|
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
pthread_mutex_unlock(&mosq->callback_mutex);
|
2018-10-25 11:03:22 +00:00
|
|
|
switch(reason_code){
|
2014-05-07 22:27:00 +00:00
|
|
|
case 0:
|
2014-07-01 21:16:53 +00:00
|
|
|
if(mosq->state != mosq_cs_disconnecting){
|
|
|
|
mosq->state = mosq_cs_connected;
|
|
|
|
}
|
2015-05-24 10:52:38 +00:00
|
|
|
message__retry_check(mosq);
|
2014-05-07 22:27:00 +00:00
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
return MOSQ_ERR_CONN_REFUSED;
|
|
|
|
default:
|
|
|
|
return MOSQ_ERR_PROTOCOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|