1 /*
2 Copyright (c) 2009-2020 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 v1.0
6 and Eclipse Distribution License v1.0 which accompany this distribution.
7 
8 The Eclipse Public License is available at
9    http://www.eclipse.org/legal/epl-v10.html
10 and the Eclipse Distribution License is available at
11   http://www.eclipse.org/org/documents/edl-v10.php.
12 
13 Contributors:
14    Roger Light - initial implementation and documentation.
15 */
16 
17 #include "config.h"
18 
19 #include <assert.h>
20 #include <stdio.h>
21 #include <string.h>
22 
23 #ifdef WITH_BROKER
24 #  include "mosquitto_broker_internal.h"
25 #endif
26 
27 #include "mosquitto.h"
28 #include "logging_mosq.h"
29 #include "memory_mosq.h"
30 #include "messages_mosq.h"
31 #include "mqtt_protocol.h"
32 #include "net_mosq.h"
33 #include "packet_mosq.h"
34 #include "read_handle.h"
35 #include "send_mosq.h"
36 #include "util_mosq.h"
37 
handle__pingreq(struct mosquitto * mosq)38 int handle__pingreq(struct mosquitto *mosq)
39 {
40 	int state;
41 
42 	assert(mosq);
43 
44 	state = mosquitto__get_state(mosq);
45 	if(state != mosq_cs_active){
46 		return MOSQ_ERR_PROTOCOL;
47 	}
48 
49 #ifdef WITH_BROKER
50 	log__printf(NULL, MOSQ_LOG_DEBUG, "Received PINGREQ from %s", mosq->id);
51 #else
52 	log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PINGREQ", mosq->id);
53 #endif
54 	return send__pingresp(mosq);
55 }
56 
handle__pingresp(struct mosquitto * mosq)57 int handle__pingresp(struct mosquitto *mosq)
58 {
59 	int state;
60 
61 	assert(mosq);
62 
63 	state = mosquitto__get_state(mosq);
64 	if(state != mosq_cs_active){
65 		return MOSQ_ERR_PROTOCOL;
66 	}
67 
68 	mosq->ping_t = 0; /* No longer waiting for a PINGRESP. */
69 #ifdef WITH_BROKER
70 	log__printf(NULL, MOSQ_LOG_DEBUG, "Received PINGRESP from %s", mosq->id);
71 #else
72 	log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PINGRESP", mosq->id);
73 #endif
74 	return MOSQ_ERR_SUCCESS;
75 }
76 
77