summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/mqtt.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-04-28 19:20:13 (GMT)
committerBrad King <brad.king@kitware.com>2022-04-28 19:21:23 (GMT)
commit30aba1ce8cedec012cec9099217d4d83d7080a1c (patch)
treee920c2c714b2f0662de839b140797da3bdc7ff64 /Utilities/cmcurl/lib/mqtt.c
parent5239672e64a85ad400ef1bdb4a9118aff2da0c3f (diff)
parent2a9bc9ebf09fbafa5378d143083434204e9f233e (diff)
downloadCMake-30aba1ce8cedec012cec9099217d4d83d7080a1c.zip
CMake-30aba1ce8cedec012cec9099217d4d83d7080a1c.tar.gz
CMake-30aba1ce8cedec012cec9099217d4d83d7080a1c.tar.bz2
Merge branch 'upstream-curl' into update-curl
* upstream-curl: curl 2022-04-27 (1669b17d)
Diffstat (limited to 'Utilities/cmcurl/lib/mqtt.c')
-rw-r--r--Utilities/cmcurl/lib/mqtt.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/Utilities/cmcurl/lib/mqtt.c b/Utilities/cmcurl/lib/mqtt.c
index fcd40b4..9bcbaa1 100644
--- a/Utilities/cmcurl/lib/mqtt.c
+++ b/Utilities/cmcurl/lib/mqtt.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2020 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2020 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2019, Björn Stenberg, <bjorn@haxx.se>
*
* This software is licensed as described in the file COPYING, which
@@ -60,6 +60,8 @@
*/
static CURLcode mqtt_do(struct Curl_easy *data, bool *done);
+static CURLcode mqtt_done(struct Curl_easy *data,
+ CURLcode status, bool premature);
static CURLcode mqtt_doing(struct Curl_easy *data, bool *done);
static int mqtt_getsock(struct Curl_easy *data, struct connectdata *conn,
curl_socket_t *sock);
@@ -74,7 +76,7 @@ const struct Curl_handler Curl_handler_mqtt = {
"MQTT", /* scheme */
mqtt_setup_conn, /* setup_connection */
mqtt_do, /* do_it */
- ZERO_NULL, /* done */
+ mqtt_done, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
@@ -344,7 +346,9 @@ end:
static CURLcode mqtt_disconnect(struct Curl_easy *data)
{
CURLcode result = CURLE_OK;
+ struct MQTT *mq = data->req.p.mqtt;
result = mqtt_send(data, (char *)"\xe0\x00", 2);
+ Curl_safefree(mq->sendleftovers);
return result;
}
@@ -384,8 +388,7 @@ static CURLcode mqtt_get_topic(struct Curl_easy *data,
{
char *path = data->state.up.path;
if(strlen(path) > 1)
- return Curl_urldecode(data, path + 1, 0, topic, topiclen,
- REJECT_NADA);
+ return Curl_urldecode(path + 1, 0, topic, topiclen, REJECT_NADA);
failf(data, "No MQTT topic found. Forgot to URL encode it?");
return CURLE_URL_MALFORMAT;
}
@@ -692,6 +695,16 @@ static CURLcode mqtt_do(struct Curl_easy *data, bool *done)
return CURLE_OK;
}
+static CURLcode mqtt_done(struct Curl_easy *data,
+ CURLcode status, bool premature)
+{
+ struct MQTT *mq = data->req.p.mqtt;
+ (void)status;
+ (void)premature;
+ Curl_safefree(mq->sendleftovers);
+ return CURLE_OK;
+}
+
static CURLcode mqtt_doing(struct Curl_easy *data, bool *done)
{
CURLcode result = CURLE_OK;
@@ -719,8 +732,14 @@ static CURLcode mqtt_doing(struct Curl_easy *data, bool *done)
case MQTT_FIRST:
/* Read the initial byte only */
result = Curl_read(data, sockfd, (char *)&mq->firstbyte, 1, &nread);
- if(!nread)
+ if(result)
break;
+ else if(!nread) {
+ failf(data, "Connection disconnected");
+ *done = TRUE;
+ result = CURLE_RECV_ERROR;
+ break;
+ }
Curl_debug(data, CURLINFO_HEADER_IN, (char *)&mq->firstbyte, 1);
/* remember the first byte */
mq->npacket = 0;