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
9a465333
Commit
9a465333
authored
Feb 26, 2018
by
Ian Craggs
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into mqttv5
parents
bf7c2936
8276dcd2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
4 deletions
+76
-4
MQTTAsync.c
src/MQTTAsync.c
+25
-1
MQTTAsync.h
src/MQTTAsync.h
+5
-0
MQTTClient.c
src/MQTTClient.c
+25
-1
MQTTClient.h
src/MQTTClient.h
+4
-0
test3.c
test/test3.c
+9
-1
test5.c
test/test5.c
+8
-1
No files found.
src/MQTTAsync.c
View file @
9a465333
/*******************************************************************************
* Copyright (c) 2009, 201
7
IBM Corp.
* Copyright (c) 2009, 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
...
...
@@ -33,6 +33,7 @@
* Ian Craggs - SNI support
* Ian Craggs - auto reconnect timing fix #218
* Ian Craggs - fix for issue #190
* Ian Craggs - check for NULL SSL options #334
*******************************************************************************/
/**
...
...
@@ -464,6 +465,20 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
goto
exit
;
}
if
(
strstr
(
serverURI
,
"://"
)
!=
NULL
)
{
if
(
strncmp
(
URI_TCP
,
serverURI
,
strlen
(
URI_TCP
))
!=
0
#if defined(OPENSSL)
&&
strncmp
(
URI_SSL
,
serverURI
,
strlen
(
URI_SSL
))
!=
0
#endif
)
{
rc
=
MQTTASYNC_BAD_PROTOCOL
;
goto
exit
;
}
}
if
(
options
&&
(
strncmp
(
options
->
struct_id
,
"MQCO"
,
4
)
!=
0
||
options
->
struct_version
!=
0
))
{
rc
=
MQTTASYNC_BAD_STRUCTURE
;
...
...
@@ -2254,6 +2269,15 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
rc
=
MQTTASYNC_BAD_STRUCTURE
;
goto
exit
;
}
#if defined(OPENSSL)
if
(
m
->
ssl
&&
options
->
ssl
==
NULL
)
{
rc
=
MQTTCLIENT_NULL_PARAMETER
;
goto
exit
;
}
#endif
if
(
options
->
will
)
/* check validity of will options structure */
{
if
(
strncmp
(
options
->
will
->
struct_id
,
"MQTW"
,
4
)
!=
0
||
(
options
->
will
->
struct_version
!=
0
&&
options
->
will
->
struct_version
!=
1
))
...
...
src/MQTTAsync.h
View file @
9a465333
...
...
@@ -172,6 +172,11 @@
* Return code: Attempting SSL connection using non-SSL version of library
*/
#define MQTTASYNC_SSL_NOT_SUPPORTED -13
/**
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTASYNC_BAD_PROTOCOL -14
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
...
...
src/MQTTClient.c
View file @
9a465333
/*******************************************************************************
* Copyright (c) 2009, 201
7
IBM Corp.
* Copyright (c) 2009, 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
...
...
@@ -32,6 +32,7 @@
* Ian Craggs - SNI support, message queue unpersist bug
* Ian Craggs - binary will message support
* Ian Craggs - waitforCompletion fix #240
* Ian Craggs - check for NULL SSL options #334
*******************************************************************************/
/**
...
...
@@ -319,6 +320,20 @@ int MQTTClient_create(MQTTClient* handle, const char* serverURI, const char* cli
goto
exit
;
}
if
(
strstr
(
serverURI
,
"://"
)
!=
NULL
)
{
if
(
strncmp
(
URI_TCP
,
serverURI
,
strlen
(
URI_TCP
))
!=
0
#if defined(OPENSSL)
&&
strncmp
(
URI_SSL
,
serverURI
,
strlen
(
URI_SSL
))
!=
0
#endif
)
{
rc
=
MQTTCLIENT_BAD_PROTOCOL
;
goto
exit
;
}
}
if
(
!
initialized
)
{
#if defined(HEAP_H)
...
...
@@ -1171,6 +1186,14 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
goto
exit
;
}
#if defined(OPENSSL)
if
(
m
->
ssl
&&
options
->
ssl
==
NULL
)
{
rc
=
MQTTCLIENT_NULL_PARAMETER
;
goto
exit
;
}
#endif
if
(
options
->
will
)
/* check validity of will options structure */
{
if
(
strncmp
(
options
->
will
->
struct_id
,
"MQTW"
,
4
)
!=
0
||
(
options
->
will
->
struct_version
!=
0
&&
options
->
will
->
struct_version
!=
1
))
...
...
@@ -1180,6 +1203,7 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
}
}
#if defined(OPENSSL)
if
(
options
->
struct_version
!=
0
&&
options
->
ssl
)
/* check validity of SSL options structure */
{
...
...
src/MQTTClient.h
View file @
9a465333
...
...
@@ -179,6 +179,10 @@
* Return code: unrecognized MQTT version
*/
#define MQTTCLIENT_BAD_MQTT_VERSION -11
/**
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTCLIENT_BAD_PROTOCOL -14
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
...
...
test/test3.c
View file @
9a465333
/*******************************************************************************
* Copyright (c) 2012, 201
7
IBM Corp.
* Copyright (c) 2012, 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
...
...
@@ -12,6 +12,7 @@
*
* Contributors:
* Allan Stockdill-Mander - initial API and implementation and/or initial documentation
* Ian Craggs - add SSL options NULL test
*******************************************************************************/
/**
...
...
@@ -570,6 +571,9 @@ int test1(struct Options options)
fprintf
(
xml
,
"<testcase classname=
\"
test3
\"
name=
\"
SSL connect fail to nonSSL MQTT server
\"
"
);
global_start_time
=
start_clock
();
rc
=
MQTTClient_create
(
&
c
,
"a b://wrong protocol"
,
"test1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
persistenceStore
);
assert
(
"bad rc from create"
,
rc
==
MQTTCLIENT_BAD_PROTOCOL
,
"rc was %d
\n
"
,
rc
);
rc
=
MQTTClient_create
(
&
c
,
options
.
connection
,
"test1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
persistenceStore
);
if
(
!
(
assert
(
"good rc from create"
,
rc
==
MQTTCLIENT_SUCCESS
,
"rc was %d
\n
"
,
rc
)))
goto
exit
;
...
...
@@ -584,6 +588,10 @@ int test1(struct Options options)
opts
.
serverURIcount
=
options
.
hacount
;
}
/* Try with ssl opts == NULL - should get error */
rc
=
MQTTClient_connect
(
c
,
&
opts
);
assert
(
"Connect should fail"
,
rc
==
MQTTCLIENT_NULL_PARAMETER
,
"rc was %d "
,
rc
);
opts
.
ssl
=
&
sslopts
;
if
(
options
.
server_key_file
!=
NULL
)
opts
.
ssl
->
trustStore
=
options
.
server_key_file
;
/*file of certificates trusted by client*/
...
...
test/test5.c
View file @
9a465333
/*******************************************************************************
* Copyright (c) 2012, 201
7
IBM Corp.
* Copyright (c) 2012, 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
...
...
@@ -613,6 +613,10 @@ int test1(struct Options options)
fprintf
(
xml
,
"<testcase classname=
\"
test5
\"
name=
\"
%s
\"
"
,
testname
);
global_start_time
=
start_clock
();
rc
=
MQTTAsync_create
(
&
c
,
"rubbish://wrong"
,
"test1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
assert
(
"bad rc from create"
,
rc
==
MQTTASYNC_BAD_PROTOCOL
,
"rc was %d
\n
"
,
rc
);
rc
=
MQTTAsync_create
(
&
c
,
options
.
connection
,
"test1"
,
MQTTCLIENT_PERSISTENCE_DEFAULT
,
NULL
);
assert
(
"good rc from create"
,
rc
==
MQTTASYNC_SUCCESS
,
"rc was %d
\n
"
,
rc
);
...
...
@@ -637,6 +641,9 @@ int test1(struct Options options)
opts
.
onFailure
=
test1OnFailure
;
opts
.
context
=
c
;
rc
=
MQTTAsync_connect
(
c
,
&
opts
);
assert
(
"Bad rc from connect"
,
rc
==
MQTTASYNC_NULL_PARAMETER
,
"rc was %d "
,
rc
);
opts
.
ssl
=
&
sslopts
;
opts
.
ssl
->
enableServerCertAuth
=
0
;
...
...
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