-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_handle_client.c
60 lines (52 loc) · 1.51 KB
/
read_handle_client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Copyright (c) 2009-2014 Roger Light <[email protected]>
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.
The Eclipse Public License is available at
https://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
https://www.eclipse.org/org/documents/edl-v10.php.
Contributors:
Roger Light - initial implementation and documentation.
*/
#include <assert.h>
#include <mosquitto.h>
#include <logging_mosq.h>
#include <memory_mosq.h>
#include <net_mosq.h>
#include <read_handle.h>
int _mosquitto_handle_connack(struct mosquitto *mosq)
{
uint8_t byte;
uint8_t result;
int rc;
assert(mosq);
_mosquitto_log_printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK", mosq->id);
rc = _mosquitto_read_byte(&mosq->in_packet, &byte); // Reserved byte, not used
if(rc) return rc;
rc = _mosquitto_read_byte(&mosq->in_packet, &result);
if(rc) return rc;
pthread_mutex_lock(&mosq->callback_mutex);
if(mosq->on_connect){
mosq->in_callback = true;
mosq->on_connect(mosq, mosq->userdata, result);
mosq->in_callback = false;
}
pthread_mutex_unlock(&mosq->callback_mutex);
switch(result){
case 0:
if(mosq->state != mosq_cs_disconnecting){
mosq->state = mosq_cs_connected;
}
return MOSQ_ERR_SUCCESS;
case 1:
case 2:
case 3:
case 4:
case 5:
return MOSQ_ERR_CONN_REFUSED;
default:
return MOSQ_ERR_PROTOCOL;
}
}