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
a8926720
Commit
a8926720
authored
May 31, 2018
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add full test1 tests for V5
parent
1b61a3bf
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1751 additions
and
180 deletions
+1751
-180
MQTTClient.c
src/MQTTClient.c
+37
-10
MQTTClient.h
src/MQTTClient.h
+4
-2
CMakeLists.txt
test/CMakeLists.txt
+36
-0
MQTTV311.py
test/MQTTV311.py
+61
-62
MQTTV5.py
test/MQTTV5.py
+1464
-0
mqttsas.py
test/mqttsas.py
+34
-10
test1.c
test/test1.c
+1
-1
test15.c
test/test15.c
+104
-87
test5.c
test/test5.c
+1
-2
test6.c
test/test6.c
+9
-6
No files found.
src/MQTTClient.c
View file @
a8926720
...
...
@@ -801,7 +801,7 @@ static void MQTTClient_closeSession(Clients* client, enum MQTTReasonCodes reason
client
->
connected
=
0
;
client
->
connect_state
=
0
;
if
(
client
->
cleansession
)
if
(
client
->
MQTTVersion
<
MQTTVERSION_5
&&
client
->
cleansession
)
MQTTClient_cleanSession
(
client
);
FUNC_EXIT
;
}
...
...
@@ -1551,7 +1551,13 @@ exit:
int
MQTTClient_subscribeMany
(
MQTTClient
handle
,
int
count
,
char
*
const
*
topic
,
int
*
qos
)
{
MQTTResponse
response
=
MQTTClient_subscribeMany5
(
handle
,
count
,
topic
,
qos
,
NULL
,
NULL
);
MQTTClients
*
m
=
handle
;
MQTTResponse
response
=
{
MQTTCLIENT_SUCCESS
,
NULL
};
if
(
m
->
c
->
MQTTVersion
>=
MQTTVERSION_5
)
response
.
reasonCode
=
MQTTCLIENT_BAD_MQTT_VERSION
;
else
response
=
MQTTClient_subscribeMany5
(
handle
,
count
,
topic
,
qos
,
NULL
,
NULL
);
return
response
.
reasonCode
;
}
...
...
@@ -1575,7 +1581,13 @@ MQTTResponse MQTTClient_subscribe5(MQTTClient handle, const char* topic, int qos
int
MQTTClient_subscribe
(
MQTTClient
handle
,
const
char
*
topic
,
int
qos
)
{
MQTTResponse
response
=
MQTTClient_subscribe5
(
handle
,
topic
,
qos
,
NULL
,
NULL
);
MQTTClients
*
m
=
handle
;
MQTTResponse
response
=
{
MQTTCLIENT_SUCCESS
,
NULL
};
if
(
m
->
c
->
MQTTVersion
>=
MQTTVERSION_5
)
response
.
reasonCode
=
MQTTCLIENT_BAD_MQTT_VERSION
;
else
response
=
MQTTClient_subscribe5
(
handle
,
topic
,
qos
,
NULL
,
NULL
);
return
response
.
reasonCode
;
}
...
...
@@ -1698,8 +1710,6 @@ MQTTResponse MQTTClient_publish5(MQTTClient handle, const char* topicName, int p
rc
=
MQTTCLIENT_DISCONNECTED
;
else
if
(
!
UTF8_validateString
(
topicName
))
rc
=
MQTTCLIENT_BAD_UTF8_STRING
;
else
if
(
m
->
c
->
MQTTVersion
>=
MQTTVERSION_5
&&
properties
==
NULL
)
rc
=
MQTTCLIENT_NULL_PARAMETER
;
if
(
rc
!=
MQTTCLIENT_SUCCESS
)
goto
exit
;
...
...
@@ -1738,7 +1748,15 @@ MQTTResponse MQTTClient_publish5(MQTTClient handle, const char* topicName, int p
p
->
msgId
=
msgid
;
p
->
MQTTVersion
=
m
->
c
->
MQTTVersion
;
if
(
m
->
c
->
MQTTVersion
>=
MQTTVERSION_5
)
{
if
(
properties
)
p
->
properties
=
*
properties
;
else
{
MQTTProperties
props
=
MQTTProperties_initializer
;
p
->
properties
=
props
;
}
}
rc
=
MQTTProtocol_startPublish
(
m
->
c
,
p
,
qos
,
retained
,
&
msg
);
...
...
@@ -1781,7 +1799,13 @@ exit:
int
MQTTClient_publish
(
MQTTClient
handle
,
const
char
*
topicName
,
int
payloadlen
,
void
*
payload
,
int
qos
,
int
retained
,
MQTTClient_deliveryToken
*
deliveryToken
)
{
MQTTResponse
rc
=
MQTTClient_publish5
(
handle
,
topicName
,
payloadlen
,
payload
,
qos
,
retained
,
NULL
,
deliveryToken
);
MQTTClients
*
m
=
handle
;
MQTTResponse
rc
=
{
MQTTCLIENT_SUCCESS
,
NULL
};
if
(
m
->
c
->
MQTTVersion
>=
MQTTVERSION_5
)
rc
.
reasonCode
=
MQTTCLIENT_BAD_MQTT_VERSION
;
else
rc
=
MQTTClient_publish5
(
handle
,
topicName
,
payloadlen
,
payload
,
qos
,
retained
,
NULL
,
deliveryToken
);
return
rc
.
reasonCode
;
}
...
...
@@ -1820,12 +1844,15 @@ exit:
int
MQTTClient_publishMessage
(
MQTTClient
handle
,
const
char
*
topicName
,
MQTTClient_message
*
message
,
MQTTClient_deliveryToken
*
deliveryToken
)
{
MQTTClients
*
m
=
handle
;
MQTTResponse
rc
=
{
MQTTCLIENT_SUCCESS
,
NULL
};
if
(
strncmp
(
message
->
struct_id
,
"MQTM"
,
4
)
!=
0
||
(
message
->
struct_version
!=
0
&&
message
->
struct_version
!=
1
))
return
MQTTCLIENT_BAD_STRUCTURE
;
rc
.
reasonCode
=
MQTTCLIENT_BAD_STRUCTURE
;
else
if
(
m
->
c
->
MQTTVersion
>=
MQTTVERSION_5
)
rc
.
reasonCode
=
MQTTCLIENT_BAD_MQTT_VERSION
;
else
rc
=
MQTTClient_publishMessage5
(
handle
,
topicName
,
message
,
deliveryToken
);
return
rc
.
reasonCode
;
}
...
...
src/MQTTClient.h
View file @
a8926720
...
...
@@ -712,6 +712,7 @@ typedef struct
* 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_1 (4) = only try version 3.1.1
* MQTTVERSION_5 (5) = only try version 5.0
*/
int
MQTTVersion
;
/**
...
...
@@ -726,7 +727,8 @@ typedef struct
/**
* Optional binary password. Only checked and used if the password option is NULL
*/
struct
{
struct
{
int
len
;
/**< binary password length */
const
void
*
data
;
/**< binary password data */
}
binarypwd
;
...
...
test/CMakeLists.txt
View file @
a8926720
...
...
@@ -110,8 +110,44 @@ ADD_TEST(
COMMAND
"test15"
"--test_no"
"1"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_TEST
(
NAME test15-2-multithread-callbacks
COMMAND
"test15"
"--test_no"
"2"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_TEST
(
NAME test15-3-connack-return-codes
COMMAND
"test15"
"--test_no"
"3"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_TEST
(
NAME test15-4-client-persistence
COMMAND
"test15"
"--test_no"
"4"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_TEST
(
NAME test15-5-disconnect-with-quiesce
COMMAND
"test15"
"--test_no"
"5"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_TEST
(
NAME test15-6-connlost-will-message
COMMAND
"test15"
"--test_no"
"6"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
ADD_TEST
(
NAME test15-7-connlost-binary-will-message
COMMAND
"test15"
"--test_no"
"7"
"--connection"
${
MQTT_TEST_BROKER
}
"--proxy_connection"
${
MQTT_TEST_PROXY
}
)
SET_TESTS_PROPERTIES
(
test15-1-single-thread-client
test15-2-multithread-callbacks
test15-3-connack-return-codes
test15-4-client-persistence
test15-5-disconnect-with-quiesce
test15-6-connlost-will-message
test15-7-connlost-binary-will-message
PROPERTIES TIMEOUT 540
)
...
...
test/MQTTV311.py
View file @
a8926720
"""
*******************************************************************
Copyright (c) 2013, 201
4
IBM Corp.
Copyright (c) 2013, 201
8
IBM Corp.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
...
...
@@ -106,10 +106,10 @@ class FixedHeaders:
self
.
RETAIN
==
fh
.
RETAIN
# and \
# self.remainingLength == fh.remainingLength
def
__
rep
r__
(
self
):
"return printable
rep
resentation of our data"
return
classNames
[
self
.
MessageType
]
+
'(DUP='
+
rep
r
(
self
.
DUP
)
+
\
", QoS="
+
repr
(
self
.
QoS
)
+
", Retain="
+
rep
r
(
self
.
RETAIN
)
def
__
st
r__
(
self
):
"return printable
st
resentation of our data"
return
classNames
[
self
.
MessageType
]
+
'(DUP='
+
st
r
(
self
.
DUP
)
+
\
", QoS="
+
str
(
self
.
QoS
)
+
", Retain="
+
st
r
(
self
.
RETAIN
)
def
pack
(
self
,
length
):
"pack data into string buffer ready for transmission down socket"
...
...
@@ -202,8 +202,8 @@ class Packets:
buffer
=
self
.
fh
.
pack
(
0
)
return
buffer
def
__
rep
r__
(
self
):
return
rep
r
(
self
.
fh
)
def
__
st
r__
(
self
):
return
st
r
(
self
.
fh
)
def
__eq__
(
self
,
packet
):
return
self
.
fh
==
packet
.
fh
if
packet
else
False
...
...
@@ -331,15 +331,15 @@ class Connects(Packets):
def
__
rep
r__
(
self
):
buf
=
rep
r
(
self
.
fh
)
+
", ProtocolName="
+
str
(
self
.
ProtocolName
)
+
", ProtocolVersion="
+
\
repr
(
self
.
ProtocolVersion
)
+
", CleanSession="
+
rep
r
(
self
.
CleanSession
)
+
\
", WillFlag="
+
rep
r
(
self
.
WillFlag
)
+
", KeepAliveTimer="
+
\
rep
r
(
self
.
KeepAliveTimer
)
+
", ClientId="
+
str
(
self
.
ClientIdentifier
)
+
\
", usernameFlag="
+
repr
(
self
.
usernameFlag
)
+
", passwordFlag="
+
rep
r
(
self
.
passwordFlag
)
def
__
st
r__
(
self
):
buf
=
st
r
(
self
.
fh
)
+
", ProtocolName="
+
str
(
self
.
ProtocolName
)
+
", ProtocolVersion="
+
\
str
(
self
.
ProtocolVersion
)
+
", CleanSession="
+
st
r
(
self
.
CleanSession
)
+
\
", WillFlag="
+
st
r
(
self
.
WillFlag
)
+
", KeepAliveTimer="
+
\
st
r
(
self
.
KeepAliveTimer
)
+
", ClientId="
+
str
(
self
.
ClientIdentifier
)
+
\
", usernameFlag="
+
str
(
self
.
usernameFlag
)
+
", passwordFlag="
+
st
r
(
self
.
passwordFlag
)
if
self
.
WillFlag
:
buf
+=
", WillQoS="
+
rep
r
(
self
.
WillQoS
)
+
\
", WillRETAIN="
+
rep
r
(
self
.
WillRETAIN
)
+
\
buf
+=
", WillQoS="
+
st
r
(
self
.
WillQoS
)
+
\
", WillRETAIN="
+
st
r
(
self
.
WillRETAIN
)
+
\
", WillTopic='"
+
self
.
WillTopic
+
\
"', WillMessage='"
+
str
(
self
.
WillMessage
)
+
"'"
if
self
.
username
:
...
...
@@ -393,8 +393,8 @@ class Connacks(Packets):
assert
self
.
fh
.
QoS
==
0
,
"[MQTT-2.1.2-1]"
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1]"
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", Session present="
+
str
((
self
.
flags
&
0x01
)
==
1
)
+
", ReturnCode="
+
rep
r
(
self
.
returnCode
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", Session present="
+
str
((
self
.
flags
&
0x01
)
==
1
)
+
", ReturnCode="
+
st
r
(
self
.
returnCode
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -421,8 +421,8 @@ class Disconnects(Packets):
assert
self
.
fh
.
QoS
==
0
,
"[MQTT-2.1.2-1]"
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1]"
def
__
rep
r__
(
self
):
return
rep
r
(
self
.
fh
)
+
")"
def
__
st
r__
(
self
):
return
st
r
(
self
.
fh
)
+
")"
class
Publishes
(
Packets
):
...
...
@@ -475,11 +475,11 @@ class Publishes(Packets):
assert
self
.
fh
.
DUP
==
False
,
"[MQTT-2.1.2-4]"
return
fhlen
+
self
.
fh
.
remainingLength
def
__
rep
r__
(
self
):
rc
=
rep
r
(
self
.
fh
)
def
__
st
r__
(
self
):
rc
=
st
r
(
self
.
fh
)
if
self
.
fh
.
QoS
!=
0
:
rc
+=
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
rc
+=
", TopicName="
+
repr
(
self
.
topicName
)
+
", Payload="
+
rep
r
(
self
.
data
)
+
")"
rc
+=
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
rc
+=
", TopicName="
+
str
(
self
.
topicName
)
+
", Payload="
+
st
r
(
self
.
data
)
+
")"
return
rc
def
__eq__
(
self
,
packet
):
...
...
@@ -520,8 +520,8 @@ class Pubacks(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1] Puback reserved bits must be 0"
return
fhlen
+
2
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId "
+
rep
r
(
self
.
messageIdentifier
)
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId "
+
st
r
(
self
.
messageIdentifier
)
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -557,8 +557,8 @@ class Pubrecs(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1] Pubrec reserved bits must be 0"
return
fhlen
+
2
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -595,8 +595,8 @@ class Pubrels(Packets):
logger
.
info
(
"[MQTT-3.6.1-1] bits in fixed header for pubrel are ok"
)
return
fhlen
+
2
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -632,8 +632,8 @@ class Pubcomps(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1] Retain should be false in Pubcomp"
return
fhlen
+
2
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -685,9 +685,9 @@ class Subscribes(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1] RETAIN must be false in subscribe"
return
fhlen
+
self
.
fh
.
remainingLength
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
\
", Data="
+
rep
r
(
self
.
data
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
\
", Data="
+
st
r
(
self
.
data
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -735,9 +735,9 @@ class Subacks(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1] Retain should be false in suback"
return
fhlen
+
self
.
fh
.
remainingLength
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
\
", Data="
+
rep
r
(
self
.
data
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
\
", Data="
+
st
r
(
self
.
data
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -787,9 +787,9 @@ class Unsubscribes(Packets):
logger
.
info
(
"[MQTT-3-10.1-1] fixed header bits are 0,0,1,0"
)
return
fhlen
+
self
.
fh
.
remainingLength
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
\
", Data="
+
rep
r
(
self
.
data
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
\
", Data="
+
st
r
(
self
.
data
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -827,8 +827,8 @@ class Unsubacks(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1]"
return
fhlen
+
self
.
fh
.
remainingLength
def
__
rep
r__
(
self
):
return
repr
(
self
.
fh
)
+
", MsgId="
+
rep
r
(
self
.
messageIdentifier
)
+
")"
def
__
st
r__
(
self
):
return
str
(
self
.
fh
)
+
", MsgId="
+
st
r
(
self
.
messageIdentifier
)
+
")"
def
__eq__
(
self
,
packet
):
return
Packets
.
__eq__
(
self
,
packet
)
and
\
...
...
@@ -855,8 +855,8 @@ class Pingreqs(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1]"
return
fhlen
def
__
rep
r__
(
self
):
return
rep
r
(
self
.
fh
)
+
")"
def
__
st
r__
(
self
):
return
st
r
(
self
.
fh
)
+
")"
class
Pingresps
(
Packets
):
...
...
@@ -879,8 +879,8 @@ class Pingresps(Packets):
assert
self
.
fh
.
RETAIN
==
False
,
"[MQTT-2.1.2-1]"
return
fhlen
def
__
rep
r__
(
self
):
return
rep
r
(
self
.
fh
)
+
")"
def
__
st
r__
(
self
):
return
st
r
(
self
.
fh
)
+
")"
classes
=
[
None
,
Connects
,
Connacks
,
Publishes
,
Pubacks
,
Pubrecs
,
Pubrels
,
Pubcomps
,
Subscribes
,
Subacks
,
Unsubscribes
,
...
...
@@ -917,4 +917,3 @@ if __name__ == "__main__":
except
:
print
(
"before:"
,
before
,
"
\n
after:"
,
after
)
print
(
"End"
)
test/MQTTV5.py
0 → 100644
View file @
a8926720
This diff is collapsed.
Click to expand it.
test/mqttsas.py
View file @
a8926720
...
...
@@ -13,6 +13,7 @@
Contributors:
Ian Craggs - initial implementation and/or documentation
Ian Craggs - add MQTTV5 support
*******************************************************************
"""
from
__future__
import
print_function
...
...
@@ -20,11 +21,15 @@ from __future__ import print_function
import
socket
,
sys
,
select
,
traceback
,
datetime
,
os
try
:
import
socketserver
import
MQTTV311
as
MQTTV3
# Trace MQTT traffic - Python 3 version
import
MQTTV311
# Trace MQTT traffic - Python 3 version
import
MQTTV5
except
:
traceback
.
print_exc
()
import
SocketServer
as
socketserver
import
MQTTV3112
as
MQTTV3
# Trace MQTT traffic - Python 2 version
import
MQTTV3112
as
MQTTV311
# Trace MQTT traffic - Python 2 version
import
MQTTV5
MQTT
=
MQTTV311
logging
=
True
myWindow
=
None
...
...
@@ -38,6 +43,7 @@ suspended = []
class
MyHandler
(
socketserver
.
StreamRequestHandler
):
def
handle
(
self
):
global
MQTT
if
not
hasattr
(
self
,
"ids"
):
self
.
ids
=
{}
if
not
hasattr
(
self
,
"versions"
):
...
...
@@ -55,12 +61,30 @@ class MyHandler(socketserver.StreamRequestHandler):
if
s
in
suspended
:
print
(
"suspended"
)
if
s
==
clients
and
s
not
in
suspended
:
inbuf
=
MQTT
V3
.
getPacket
(
clients
)
# get one packet
inbuf
=
MQTT
.
getPacket
(
clients
)
# get one packet
if
inbuf
==
None
:
break
try
:
packet
=
MQTTV3
.
unpackPacket
(
inbuf
)
if
packet
.
fh
.
MessageType
==
MQTTV3
.
PUBLISH
and
\
# if connect, this could be MQTTV3 or MQTTV5
if
inbuf
[
0
]
>>
4
==
1
:
# connect packet
protocol_string
=
b
'MQTT'
pos
=
inbuf
.
find
(
protocol_string
)
if
pos
!=
-
1
:
version
=
inbuf
[
pos
+
len
(
protocol_string
)]
if
version
==
5
:
MQTT
=
MQTTV5
else
:
MQTT
=
MQTTV311
packet
=
MQTT
.
unpackPacket
(
inbuf
)
if
hasattr
(
packet
.
fh
,
"MessageType"
):
packet_type
=
packet
.
fh
.
MessageType
publish_type
=
MQTT
.
PUBLISH
connect_type
=
MQTT
.
CONNECT
else
:
packet_type
=
packet
.
fh
.
PacketType
publish_type
=
MQTT
.
PacketTypes
.
PUBLISH
connect_type
=
MQTT
.
PacketTypes
.
CONNECT
if
packet_type
==
publish_type
and
\
packet
.
topicName
==
"MQTTSAS topic"
and
\
packet
.
data
==
b
"TERMINATE"
:
print
(
"Terminating client"
,
self
.
ids
[
id
(
clients
)])
...
...
@@ -68,26 +92,26 @@ class MyHandler(socketserver.StreamRequestHandler):
clients
.
close
()
terminated
=
True
break
elif
packet
.
fh
.
MessageType
==
MQTTV3
.
PUBLISH
and
\
elif
packet
_type
==
publish_type
and
\
packet
.
topicName
==
"MQTTSAS topic"
and
\
packet
.
data
==
b
"TERMINATE_SERVER"
:
print
(
"Suspending client "
,
self
.
ids
[
id
(
clients
)])
suspended
.
append
(
clients
)
elif
packet
.
fh
.
MessageType
==
MQTTV3
.
CONNECT
:
elif
packet
_type
==
connect_type
:
self
.
ids
[
id
(
clients
)]
=
packet
.
ClientIdentifier
self
.
versions
[
id
(
clients
)]
=
3
print
(
timestamp
()
,
"C to S"
,
self
.
ids
[
id
(
clients
)],
rep
r
(
packet
))
print
(
timestamp
()
,
"C to S"
,
self
.
ids
[
id
(
clients
)],
st
r
(
packet
))
#print([hex(b) for b in inbuf])
#print(inbuf)
except
:
traceback
.
print_exc
()
brokers
.
send
(
inbuf
)
# pass it on
elif
s
==
brokers
:
inbuf
=
MQTT
V3
.
getPacket
(
brokers
)
# get one packet
inbuf
=
MQTT
.
getPacket
(
brokers
)
# get one packet
if
inbuf
==
None
:
break
try
:
print
(
timestamp
(),
"S to C"
,
self
.
ids
[
id
(
clients
)],
repr
(
MQTTV3
.
unpackPacket
(
inbuf
)))
print
(
timestamp
(),
"S to C"
,
self
.
ids
[
id
(
clients
)],
str
(
MQTT
.
unpackPacket
(
inbuf
)))
except
:
traceback
.
print_exc
()
clients
.
send
(
inbuf
)
...
...
test/test1.c
View file @
a8926720
...
...
@@ -1166,7 +1166,7 @@ int main(int argc, char** argv)
fprintf
(
xml
,
"<testsuite name=
\"
test1
\"
tests=
\"
%d
\"
>
\n
"
,
(
int
)(
ARRAY_SIZE
(
tests
)
-
1
));
setenv
(
"MQTT_C_CLIENT_TRACE"
,
"ON"
,
1
);
setenv
(
"MQTT_C_CLIENT_TRACE_LEVEL"
,
"ERROR"
,
0
);
setenv
(
"MQTT_C_CLIENT_TRACE_LEVEL"
,
"ERROR"
,
1
);
getopts
(
argc
,
argv
);
...
...
test/test15.c
View file @
a8926720
This diff is collapsed.
Click to expand it.
test/test5.c
View file @
a8926720
...
...
@@ -2056,8 +2056,7 @@ int test7(struct Options options)
{
char
*
testname
=
"test7"
;
int
subsqos
=
2
;
AsyncTestClient
tc
=
AsyncTestClient_initializer
;
AsyncTestClient
tc
=
AsyncTestClient_initializer
;
MQTTAsync
c
;
MQTTAsync_connectOptions
opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_willOptions
wopts
=
MQTTAsync_willOptions_initializer
;
...
...
test/test6.c
View file @
a8926720
...
...
@@ -61,7 +61,7 @@ struct
int
persistence
;
}
opts
=
{
"tcp://localhost:188
5
"
,
"tcp://localhost:188
4
"
,
NULL
,
0
,
"tcp://localhost:7777"
,
...
...
@@ -297,7 +297,7 @@ void control_connectionLost(void* context, char* cause)
*/
int
control_messageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTAsync_message
*
m
)
{
MyLog
(
LOGA_ALWAYS
,
"Control message arrived: %.*s %s"
,
MyLog
(
LOGA_ALWAYS
,
"Control message arrived: %.*s
wait message:
%s"
,
m
->
payloadlen
,
m
->
payload
,
(
wait_message
==
NULL
)
?
"None"
:
wait_message
);
if
(
strncmp
(
m
->
payload
,
"stop"
,
4
)
==
0
)
{
...
...
@@ -307,12 +307,14 @@ int control_messageArrived(void* context, char* topicName, int topicLen, MQTTAsy
else
if
(
wait_message
!=
NULL
&&
strncmp
(
wait_message
,
m
->
payload
,
strlen
(
wait_message
))
==
0
)
{
MyLog
(
LOGA_ALWAYS
,
"Wait message %s found"
,
wait_message
);
control_found
=
1
;
wait_message
=
NULL
;
}
else
if
(
wait_message2
!=
NULL
&&
strncmp
(
wait_message2
,
m
->
payload
,
strlen
(
wait_message2
))
==
0
)
{
MyLog
(
LOGA_ALWAYS
,
"Wait message2 %s found"
,
wait_message
);
control_found
=
2
;
wait_message2
=
NULL
;
}
...
...
@@ -351,7 +353,7 @@ int control_wait(char* message)
sprintf
(
buf
,
"waiting for: %s"
,
message
);
control_send
(
buf
);
MyLog
(
LOGA_ALWAYS
,
"w
aiting for: %s"
,
message
);
MyLog
(
LOGA_ALWAYS
,
"W
aiting for: %s"
,
message
);
while
(
control_found
==
0
&&
stopping
==
0
)
{
if
(
++
count
==
300
)
...
...
@@ -362,6 +364,7 @@ int control_wait(char* message)
}
MySleep
(
1000
);
}
MyLog
(
LOGA_ALWAYS
,
"Control message found: %s, control_found %d"
,
message
,
control_found
);
return
control_found
;
}
...
...
@@ -377,7 +380,7 @@ int control_which(char* message1, char* message2)
while
(
control_found
==
0
)
{
if
(
++
count
==
300
)
return
0
;
/* time out and tell the caller the message was not found */
break
;
/* time out and tell the caller the message was not found */
MySleep
(
1000
);
}
return
control_found
;
...
...
@@ -750,7 +753,7 @@ void client_onSubscribe(void* context, MQTTAsync_successData* response)
void
client_onFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
MQTTAsync
c
=
(
MQTTAsync
)
context
;
MyLog
(
LOGA_
DEBUG
,
"In failure callback"
);
MyLog
(
LOGA_
INFO
,
"In failure callback"
);
client_subscribed
=
-
1
;
}
...
...
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