Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
paho.mqtt.c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eclipse
paho.mqtt.c
Commits
2d2bd98c
Commit
2d2bd98c
authored
Jun 05, 2014
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MQTT 3.1.1 support - sessionPresent for MQTTClient
Bug: 436049
parent
3b79c88c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
568 additions
and
18 deletions
+568
-18
MQTTAsync.h
src/MQTTAsync.h
+8
-1
MQTTClient.c
src/MQTTClient.c
+16
-3
MQTTClient.h
src/MQTTClient.h
+26
-12
MQTTPacket.h
src/MQTTPacket.h
+19
-1
MQTTPacketOut.c
src/MQTTPacketOut.c
+1
-1
test_mqtt4sync.c
test/test_mqtt4sync.c
+498
-0
No files found.
src/MQTTAsync.h
View file @
2d2bd98c
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
* @cond MQTTAsync_main
* @cond MQTTAsync_main
* @mainpage Asynchronous MQTT client library for C
* @mainpage Asynchronous MQTT client library for C
*
*
* © Copyright IBM Corp. 2009, 201
3
* © Copyright IBM Corp. 2009, 201
4
*
*
* @brief An Asynchronous MQTT client library for C.
* @brief An Asynchronous MQTT client library for C.
*
*
...
@@ -333,6 +333,13 @@ typedef struct
...
@@ -333,6 +333,13 @@ typedef struct
MQTTAsync_message
message
;
MQTTAsync_message
message
;
char
*
destinationName
;
char
*
destinationName
;
}
pub
;
}
pub
;
/* For connect, the server connected to, MQTT version used, and sessionPresent flag */
struct
{
char
*
serverURI
;
int
MQTTVersion
;
int
sessionPresent
;
}
connect
;
}
alt
;
}
alt
;
}
MQTTAsync_successData
;
}
MQTTAsync_successData
;
...
...
src/MQTTClient.c
View file @
2d2bd98c
...
@@ -762,6 +762,7 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
...
@@ -762,6 +762,7 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
{
{
MQTTClients
*
m
=
handle
;
MQTTClients
*
m
=
handle
;
int
rc
=
SOCKET_ERROR
;
int
rc
=
SOCKET_ERROR
;
int
sessionPresent
=
0
;
FUNC_ENTRY
;
FUNC_ENTRY
;
if
(
m
->
ma
&&
!
running
)
if
(
m
->
ma
&&
!
running
)
...
@@ -890,6 +891,8 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
...
@@ -890,6 +891,8 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
m
->
c
->
connected
=
1
;
m
->
c
->
connected
=
1
;
m
->
c
->
good
=
1
;
m
->
c
->
good
=
1
;
m
->
c
->
connect_state
=
0
;
m
->
c
->
connect_state
=
0
;
if
(
MQTTVersion
==
4
)
sessionPresent
=
connack
->
flags
.
bits
.
sessionPresent
;
if
(
m
->
c
->
cleansession
)
if
(
m
->
c
->
cleansession
)
rc
=
MQTTClient_cleanSession
(
m
->
c
);
rc
=
MQTTClient_cleanSession
(
m
->
c
);
if
(
m
->
c
->
outboundMsgs
->
count
>
0
)
if
(
m
->
c
->
outboundMsgs
->
count
>
0
)
...
@@ -910,9 +913,17 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
...
@@ -910,9 +913,17 @@ int MQTTClient_connectURIVersion(MQTTClient handle, MQTTClient_connectOptions* o
m
->
pack
=
NULL
;
m
->
pack
=
NULL
;
}
}
}
}
exit:
exit:
if
(
rc
!=
MQTTCLIENT_SUCCESS
)
if
(
rc
==
MQTTCLIENT_SUCCESS
)
{
if
(
options
->
struct_version
==
4
)
/* means we have to fill out return values */
{
options
->
returned
.
serverURI
=
serverURI
;
options
->
returned
.
MQTTVersion
=
MQTTVersion
;
options
->
returned
.
sessionPresent
=
sessionPresent
;
}
}
else
{
{
Thread_unlock_mutex
(
mqttclient_mutex
);
Thread_unlock_mutex
(
mqttclient_mutex
);
MQTTClient_disconnect1
(
handle
,
0
,
0
,
(
MQTTVersion
==
3
));
/* not "internal" because we don't want to call connection lost */
MQTTClient_disconnect1
(
handle
,
0
,
0
,
(
MQTTVersion
==
3
));
/* not "internal" because we don't want to call connection lost */
...
@@ -1046,7 +1057,7 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
...
@@ -1046,7 +1057,7 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
if
(
strncmp
(
options
->
struct_id
,
"MQTC"
,
4
)
!=
0
||
if
(
strncmp
(
options
->
struct_id
,
"MQTC"
,
4
)
!=
0
||
(
options
->
struct_version
!=
0
&&
options
->
struct_version
!=
1
&&
options
->
struct_version
!=
2
(
options
->
struct_version
!=
0
&&
options
->
struct_version
!=
1
&&
options
->
struct_version
!=
2
&&
options
->
struct_version
!=
3
))
&&
options
->
struct_version
!=
3
&&
options
->
struct_version
!=
4
))
{
{
rc
=
MQTTCLIENT_BAD_STRUCTURE
;
rc
=
MQTTCLIENT_BAD_STRUCTURE
;
goto
exit
;
goto
exit
;
...
@@ -1298,6 +1309,8 @@ int MQTTClient_subscribe(MQTTClient handle, char* topic, int qos)
...
@@ -1298,6 +1309,8 @@ int MQTTClient_subscribe(MQTTClient handle, char* topic, int qos)
FUNC_ENTRY
;
FUNC_ENTRY
;
rc
=
MQTTClient_subscribeMany
(
handle
,
1
,
&
topic
,
&
qos
);
rc
=
MQTTClient_subscribeMany
(
handle
,
1
,
&
topic
,
&
qos
);
if
(
qos
==
MQTT_BAD_SUBSCRIBE
)
/* addition for MQTT 3.1.1 - error code from subscribe */
rc
=
MQTT_BAD_SUBSCRIBE
;
FUNC_EXIT_RC
(
rc
);
FUNC_EXIT_RC
(
rc
);
return
rc
;
return
rc
;
}
}
...
...
src/MQTTClient.h
View file @
2d2bd98c
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
* @endcond
* @endcond
* @cond MQTTClient_main
* @cond MQTTClient_main
* @mainpage MQTT Client library for C
* @mainpage MQTT Client library for C
* © Copyright IBM Corp. 2009, 201
3
* © Copyright IBM Corp. 2009, 201
4
*
*
* @brief An MQTT client library in C.
* @brief An MQTT client library in C.
*
*
...
@@ -173,6 +173,10 @@
...
@@ -173,6 +173,10 @@
* MQTT version to connect with: 3.1.1
* MQTT version to connect with: 3.1.1
*/
*/
#define MQTTVERSION_3_1_1 4
#define MQTTVERSION_3_1_1 4
/**
* Bad return code from subscribe, as defined in the 3.1.1 specification
*/
#define MQTT_BAD_SUBSCRIBE 0x80
/**
/**
* A handle representing an MQTT client. A valid client handle is available
* A handle representing an MQTT client. A valid client handle is available
...
@@ -504,11 +508,12 @@ typedef struct
...
@@ -504,11 +508,12 @@ typedef struct
{
{
/** The eyecatcher for this structure. must be MQTC. */
/** The eyecatcher for this structure. must be MQTC. */
char
struct_id
[
4
];
char
struct_id
[
4
];
/** The version number of this structure. Must be 0, 1, 2 or 3.
/** The version number of this structure. Must be 0, 1, 2, 3 or 4.
* 0 signifies no SSL options and no serverURIs
* 0 signifies no SSL options and no serverURIs
* 1 signifies no serverURIs
* 1 signifies no serverURIs
* 2 signifies no MQTTVersion
* 2 signifies no MQTTVersion
*/
* 3 signifies no returned values
*/
int
struct_version
;
int
struct_version
;
/** The "keep alive" interval, measured in seconds, defines the maximum time
/** The "keep alive" interval, measured in seconds, defines the maximum time
* that should pass without communication between the client and the server
* that should pass without communication between the client and the server
...
@@ -599,15 +604,24 @@ typedef struct
...
@@ -599,15 +604,24 @@ typedef struct
*/
*/
char
**
serverURIs
;
char
**
serverURIs
;
/**
/**
* Sets the version of MQTT to be used on the connect.
* Sets the version of MQTT to be used on the connect.
* MQTTVERSION_DEFAULT (0) = default: start with 3.1.1, and if that fails, fall back to 3.1
* MQTTVERSION_DEFAULT (0) = default: start with 3.1.1, and if that fails, fall back to 3.1
* MQTTVERSION_3_1 (3) = only try version 3.1
* MQTTVERSION_3_1 (3) = only try version 3.1
* MQTTVERSION_3_1_1 (4) = only try version 3.1.1
* MQTTVERSION_3_1_1 (4) = only try version 3.1.1
*/
*/
int
MQTTVersion
;
int
MQTTVersion
;
/**
* Returned from the connect when the MQTT version used to connect is 3.1.1
*/
struct
{
char
*
serverURI
;
/**< the serverURI connected to */
int
MQTTVersion
;
/**< the MQTT version used to connect with */
int
sessionPresent
;
/**< if the MQTT version is 3.1.1, the value of sessionPresent returned in the connack */
}
returned
;
}
MQTTClient_connectOptions
;
}
MQTTClient_connectOptions
;
#define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'},
3
, 60, 1, 1, NULL, NULL, NULL, 30, 20, NULL, 0, NULL, 0}
#define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'},
4
, 60, 1, 1, NULL, NULL, NULL, 30, 20, NULL, 0, NULL, 0}
/**
/**
* MQTTClient_libraryInfo is used to store details relating to the currently used
* MQTTClient_libraryInfo is used to store details relating to the currently used
...
...
src/MQTTPacket.h
View file @
2d2bd98c
/*******************************************************************************
/*******************************************************************************
* Copyright (c) 2009, 201
3
IBM Corp.
* Copyright (c) 2009, 201
4
IBM Corp.
*
*
* All rights reserved. This program and the accompanying materials
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* are made available under the terms of the Eclipse Public License v1.0
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* Contributors:
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs, Allan Stockdill-Mander - SSL updates
* Ian Craggs, Allan Stockdill-Mander - SSL updates
* Ian Craggs - MQTT 3.1.1 support
*******************************************************************************/
*******************************************************************************/
#if !defined(MQTTPACKET_H)
#if !defined(MQTTPACKET_H)
...
@@ -120,6 +121,23 @@ typedef struct
...
@@ -120,6 +121,23 @@ typedef struct
typedef
struct
typedef
struct
{
{
Header
header
;
/**< MQTT header byte */
Header
header
;
/**< MQTT header byte */
union
{
unsigned
char
all
;
/**< all connack flags */
#if defined(REVERSED)
struct
{
unsigned
int
reserved
:
7
;
/**< message type nibble */
bool
sessionPresent
:
1
;
/**< was a session found on the server? */
}
bits
;
#else
struct
{
bool
sessionPresent
:
1
;
/**< was a session found on the server? */
unsigned
int
reserved
:
7
;
/**< message type nibble */
}
bits
;
#endif
}
flags
;
/**< connack flags byte */
char
rc
;
/**< connack return code */
char
rc
;
/**< connack return code */
}
Connack
;
}
Connack
;
...
...
src/MQTTPacketOut.c
View file @
2d2bd98c
...
@@ -123,7 +123,7 @@ void* MQTTPacket_connack(unsigned char aHeader, char* data, int datalen)
...
@@ -123,7 +123,7 @@ void* MQTTPacket_connack(unsigned char aHeader, char* data, int datalen)
FUNC_ENTRY
;
FUNC_ENTRY
;
pack
->
header
.
byte
=
aHeader
;
pack
->
header
.
byte
=
aHeader
;
readChar
(
&
curdata
);
/* reserved byte */
pack
->
flags
.
all
=
readChar
(
&
curdata
);
pack
->
rc
=
readChar
(
&
curdata
);
pack
->
rc
=
readChar
(
&
curdata
);
FUNC_EXIT
;
FUNC_EXIT
;
return
pack
;
return
pack
;
...
...
test/test_mqtt4sync.c
0 → 100644
View file @
2d2bd98c
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment