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
77cc4fb9
Commit
77cc4fb9
authored
May 04, 2018
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cleanstart and session expiry to async test/client
parent
ced0d0ef
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
117 deletions
+137
-117
Clients.h
src/Clients.h
+3
-1
MQTTAsync.c
src/MQTTAsync.c
+44
-16
MQTTAsync.h
src/MQTTAsync.h
+9
-1
MQTTPacketOut.c
src/MQTTPacketOut.c
+4
-1
MQTTProperties.c
src/MQTTProperties.c
+50
-0
MQTTProperties.h
src/MQTTProperties.h
+3
-0
test45.c
test/test45.c
+24
-98
No files found.
src/Clients.h
View file @
77cc4fb9
...
...
@@ -94,7 +94,8 @@ typedef struct
const
char
*
username
;
/**< MQTT v3.1 user name */
int
passwordlen
;
/**< MQTT password length */
const
void
*
password
;
/**< MQTT v3.1 binary password */
unsigned
int
cleansession
:
1
;
/**< MQTT clean session flag */
unsigned
int
cleansession
:
1
;
/**< MQTT V3 clean session flag */
unsigned
int
cleanstart
:
1
;
/**< MQTT V5 clean start flag */
unsigned
int
connected
:
1
;
/**< whether it is currently connected */
unsigned
int
good
:
1
;
/**< if we have an error on the socket we turn this off */
unsigned
int
ping_outstanding
:
1
;
...
...
@@ -113,6 +114,7 @@ typedef struct
MQTTClient_persistence
*
persistence
;
/* a persistence implementation */
void
*
context
;
/* calling context - used when calling disconnect_internal */
int
MQTTVersion
;
int
sessionExpiry
;
/**< MQTT 5 session expiry */
#if defined(OPENSSL)
MQTTClient_SSLOptions
*
sslopts
;
SSL_SESSION
*
session
;
/***< SSL session pointer for fast handhake */
...
...
src/MQTTAsync.c
View file @
77cc4fb9
...
...
@@ -1913,7 +1913,7 @@ static int MQTTAsync_completeConnection(MQTTAsyncs* m, MQTTPacket* pack)
m
->
c
->
connected
=
1
;
m
->
c
->
good
=
1
;
m
->
c
->
connect_state
=
0
;
if
(
m
->
c
->
cleansession
)
if
(
m
->
c
->
cleansession
||
m
->
c
->
cleanstart
)
rc
=
MQTTAsync_cleanSession
(
m
->
c
);
if
(
m
->
c
->
outboundMsgs
->
count
>
0
)
{
...
...
@@ -2360,7 +2360,8 @@ static void MQTTAsync_closeSession(Clients* client, enum MQTTReasonCodes reasonC
FUNC_ENTRY
;
MQTTAsync_closeOnly
(
client
,
reasonCode
,
props
);
if
(
client
->
cleansession
)
if
(
client
->
cleansession
||
(
client
->
MQTTVersion
>=
MQTTVERSION_5
&&
client
->
sessionExpiry
==
0
))
MQTTAsync_cleanSession
(
client
);
FUNC_EXIT
;
...
...
@@ -2555,6 +2556,25 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
rc
=
MQTTASYNC_BAD_UTF8_STRING
;
goto
exit
;
}
if
(
options
->
MQTTVersion
>=
MQTTVERSION_5
&&
options
->
struct_version
<
6
)
{
rc
=
MQTTASYNC_BAD_STRUCTURE
;
goto
exit
;
}
if
(
options
->
MQTTVersion
>=
MQTTVERSION_5
&&
options
->
cleansession
!=
0
)
{
rc
=
MQTTASYNC_BAD_MQTTV5_OPTIONS
;
goto
exit
;
}
if
(
options
->
MQTTVersion
<
MQTTVERSION_5
)
{
if
(
options
->
cleanstart
!=
0
||
options
->
onFailure5
||
options
->
onSuccess5
||
options
->
connectProperties
||
options
->
willProperties
)
{
rc
=
MQTTASYNC_BAD_MQTTV5_OPTIONS
;
goto
exit
;
}
}
m
->
connect
.
onSuccess
=
options
->
onSuccess
;
m
->
connect
.
onFailure
=
options
->
onFailure
;
...
...
@@ -2728,28 +2748,36 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
free
(
m
->
connectProps
);
m
->
connectProps
=
NULL
;
}
if
(
options
->
struct_version
>=
6
&&
options
->
connectProperties
)
{
MQTTProperties
initialized
=
MQTTProperties_initializer
;
m
->
connectProps
=
malloc
(
sizeof
(
MQTTProperties
));
*
m
->
connectProps
=
initialized
;
*
m
->
connectProps
=
MQTTProperties_copy
(
options
->
connectProperties
);
}
if
(
m
->
willProps
)
{
MQTTProperties_free
(
m
->
willProps
);
free
(
m
->
willProps
);
m
->
willProps
=
NULL
;
}
if
(
options
->
struct_version
>=
6
&&
options
->
willProperties
)
if
(
options
->
struct_version
>=
6
)
{
MQTTProperties
initialized
=
MQTTProperties_initializer
;
if
(
options
->
connectProperties
)
{
MQTTProperties
initialized
=
MQTTProperties_initializer
;
m
->
willProps
=
malloc
(
sizeof
(
MQTTProperties
));
*
m
->
willProps
=
initialized
;
*
m
->
willProps
=
MQTTProperties_copy
(
options
->
willProperties
);
m
->
connectProps
=
malloc
(
sizeof
(
MQTTProperties
));
*
m
->
connectProps
=
initialized
;
*
m
->
connectProps
=
MQTTProperties_copy
(
options
->
connectProperties
);
if
(
MQTTProperties_hasProperty
(
options
->
connectProperties
,
SESSION_EXPIRY_INTERVAL
))
m
->
c
->
sessionExpiry
=
MQTTProperties_getNumericValue
(
options
->
connectProperties
,
SESSION_EXPIRY_INTERVAL
);
}
if
(
options
->
willProperties
)
{
MQTTProperties
initialized
=
MQTTProperties_initializer
;
m
->
willProps
=
malloc
(
sizeof
(
MQTTProperties
));
*
m
->
willProps
=
initialized
;
*
m
->
willProps
=
MQTTProperties_copy
(
options
->
willProperties
);
}
m
->
c
->
cleanstart
=
options
->
cleanstart
;
}
/* Add connect request to operation queue */
...
...
src/MQTTAsync.h
View file @
77cc4fb9
...
...
@@ -180,6 +180,10 @@
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTASYNC_BAD_PROTOCOL -14
/**
* Return code: don't use MQTTV5 options if MQTT 3 is chosen
*/
#define MQTTASYNC_BAD_MQTTV5_OPTIONS -15
/**
...
...
@@ -989,7 +993,11 @@ typedef struct
#define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 6, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60, {0, NULL}, 0, NULL, NULL, NULL, NULL}
NULL, NULL, NULL, NULL, 0, NULL, MQTTVERSION_DEFAULT, 0, 1, 60, {0, NULL}, 0, NULL, NULL, NULL, NULL}
#define MQTTAsync_connectOptions_initializer5 { {'M', 'Q', 'T', 'C'}, 6, 60, 0, 10, NULL, NULL, NULL, 30, 0,\
NULL, NULL, NULL, NULL, 0, NULL, MQTTVERSION_5, 0, 1, 60, {0, NULL}, 1, NULL, NULL, NULL, NULL}
/**
* This function attempts to connect a previously-created client (see
...
...
src/MQTTPacketOut.c
View file @
77cc4fb9
...
...
@@ -85,7 +85,10 @@ int MQTTPacket_send_connect(Clients* client, int MQTTVersion,
goto
exit
;
packet
.
flags
.
all
=
0
;
packet
.
flags
.
bits
.
cleanstart
=
client
->
cleansession
;
if
(
MQTTVersion
>=
MQTTVERSION_5
)
packet
.
flags
.
bits
.
cleanstart
=
client
->
cleanstart
;
else
packet
.
flags
.
bits
.
cleanstart
=
client
->
cleansession
;
packet
.
flags
.
bits
.
will
=
(
client
->
will
)
?
1
:
0
;
if
(
packet
.
flags
.
bits
.
will
)
{
...
...
src/MQTTProperties.c
View file @
77cc4fb9
...
...
@@ -414,3 +414,53 @@ MQTTProperties MQTTProperties_copy(const MQTTProperties* props)
FUNC_EXIT
;
return
result
;
}
int
MQTTProperties_hasProperty
(
MQTTProperties
*
props
,
int
propid
)
{
int
i
=
0
;
int
found
=
0
;
for
(
i
=
0
;
i
<
props
->
count
;
++
i
)
{
if
(
propid
==
props
->
array
[
i
].
identifier
)
{
found
=
1
;
break
;
}
}
return
found
;
}
int
MQTTProperties_getNumericValue
(
MQTTProperties
*
props
,
int
propid
)
{
int
i
=
0
;
int
rc
=
-
9999999
;
for
(
i
=
0
;
i
<
props
->
count
;
++
i
)
{
int
id
=
props
->
array
[
i
].
identifier
;
if
(
id
==
propid
)
{
switch
(
MQTTProperty_getType
(
id
))
{
case
PROPERTY_TYPE_BYTE
:
rc
=
props
->
array
[
i
].
value
.
byte
;
break
;
case
TWO_BYTE_INTEGER
:
rc
=
props
->
array
[
i
].
value
.
integer2
;
break
;
case
FOUR_BYTE_INTEGER
:
case
VARIABLE_BYTE_INTEGER
:
rc
=
props
->
array
[
i
].
value
.
integer4
;
break
;
default:
rc
=
-
999999
;
break
;
}
}
}
return
rc
;
}
src/MQTTProperties.h
View file @
77cc4fb9
...
...
@@ -119,4 +119,7 @@ DLLExport void MQTTProperties_free(MQTTProperties* properties);
MQTTProperties
MQTTProperties_copy
(
const
MQTTProperties
*
props
);
DLLExport
int
MQTTProperties_hasProperty
(
MQTTProperties
*
props
,
int
propid
);
DLLExport
int
MQTTProperties_getNumericValue
(
MQTTProperties
*
props
,
int
propid
);
#endif
/* MQTTPROPERTIES_H */
test/test45.c
View file @
77cc4fb9
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