Commit 205a5a20 authored by Ian Craggs's avatar Ian Craggs

Update utilities for MQTT V5 and websockets #504

parent ea99febb
...@@ -87,9 +87,12 @@ HEADERS_A = $(HEADERS) ...@@ -87,9 +87,12 @@ HEADERS_A = $(HEADERS)
SAMPLE_FILES_C = paho_cs_pub paho_cs_sub MQTTClient_publish MQTTClient_publish_async MQTTClient_subscribe SAMPLE_FILES_C = paho_cs_pub paho_cs_sub MQTTClient_publish MQTTClient_publish_async MQTTClient_subscribe
SYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_C}} SYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_C}}
SAMPLE_FILES_A = paho_c_pub paho_c_sub MQTTAsync_subscribe MQTTAsync_publish SAMPLE_FILES_A = MQTTAsync_subscribe MQTTAsync_publish
ASYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_A}} ASYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_A}}
UTIL_FILES_AS = paho_c_pub paho_c_sub
ASYNC_UTILS = ${addprefix ${blddir}/samples/,${UTIL_FILES_AS}}
TEST_FILES_C = test1 test15 test2 sync_client_test test_mqtt4sync test10 TEST_FILES_C = test1 test15 test2 sync_client_test test_mqtt4sync test10
SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}} SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}}
...@@ -127,7 +130,7 @@ MQTTLIB_A_TARGET = ${blddir}/lib${MQTTLIB_A}.so.${VERSION} ...@@ -127,7 +130,7 @@ MQTTLIB_A_TARGET = ${blddir}/lib${MQTTLIB_A}.so.${VERSION}
MQTTLIB_AS_TARGET = ${blddir}/lib${MQTTLIB_AS}.so.${VERSION} MQTTLIB_AS_TARGET = ${blddir}/lib${MQTTLIB_AS}.so.${VERSION}
MQTTVERSION_TARGET = ${blddir}/MQTTVersion MQTTVERSION_TARGET = ${blddir}/MQTTVersion
CCFLAGS_SO = -g -fPIC $(CFLAGS) -Os -Wall -fvisibility=hidden -I$(blddir_work) CCFLAGS_SO = -g -fPIC $(CFLAGS) -Os -Wall -fvisibility=hidden -I$(blddir_work) -fpermissive
FLAGS_EXE = $(LDFLAGS) -I ${srcdir} -lpthread -L ${blddir} FLAGS_EXE = $(LDFLAGS) -I ${srcdir} -lpthread -L ${blddir}
FLAGS_EXES = $(LDFLAGS) -I ${srcdir} ${START_GROUP} -lpthread -lssl -lcrypto ${END_GROUP} -L ${blddir} FLAGS_EXES = $(LDFLAGS) -I ${srcdir} ${START_GROUP} -lpthread -lssl -lcrypto ${END_GROUP} -L ${blddir}
...@@ -178,7 +181,7 @@ endif ...@@ -178,7 +181,7 @@ endif
all: build all: build
build: | mkdir ${MQTTLIB_C_TARGET} ${MQTTLIB_CS_TARGET} ${MQTTLIB_A_TARGET} ${MQTTLIB_AS_TARGET} ${MQTTVERSION_TARGET} ${SYNC_SAMPLES} ${ASYNC_SAMPLES} ${SYNC_TESTS} ${SYNC_SSL_TESTS} ${ASYNC_TESTS} ${ASYNC_SSL_TESTS} build: | mkdir ${MQTTLIB_C_TARGET} ${MQTTLIB_CS_TARGET} ${MQTTLIB_A_TARGET} ${MQTTLIB_AS_TARGET} ${MQTTVERSION_TARGET} ${SYNC_SAMPLES} ${ASYNC_SAMPLES} ${ASYNC_UTILS} ${SYNC_TESTS} ${SYNC_SSL_TESTS} ${ASYNC_TESTS} ${ASYNC_SSL_TESTS}
clean: clean:
rm -rf ${blddir}/* rm -rf ${blddir}/*
...@@ -202,10 +205,13 @@ ${ASYNC_SSL_TESTS}: ${blddir}/test/%: ${srcdir}/../test/%.c $(MQTTLIB_CS_TARGET) ...@@ -202,10 +205,13 @@ ${ASYNC_SSL_TESTS}: ${blddir}/test/%: ${srcdir}/../test/%.c $(MQTTLIB_CS_TARGET)
${CC} -g -o $@ $< -l${MQTTLIB_AS} ${FLAGS_EXES} ${CC} -g -o $@ $< -l${MQTTLIB_AS} ${FLAGS_EXES}
${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/samples/%.c $(MQTTLIB_C_TARGET) ${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/samples/%.c $(MQTTLIB_C_TARGET)
${CC} -o $@ $< -l${MQTTLIB_C} ${FLAGS_EXE} ${CC} -o $@ $< -l${MQTTLIB_CS} ${FLAGS_EXES}
${ASYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/samples/%.c $(MQTTLIB_A_TARGET) ${ASYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/samples/%.c $(MQTTLIB_A_TARGET)
${CC} -o $@ $< -l${MQTTLIB_A} ${FLAGS_EXE} ${CC} -o $@ $< -l${MQTTLIB_AS} ${FLAGS_EXES}
${ASYNC_UTILS}: ${blddir}/samples/%: ${srcdir}/samples/%.c $(MQTTLIB_AS_TARGET)
${CC} -o $@ $< -l${MQTTLIB_AS} ${FLAGS_EXES} ${srcdir}/samples/pubsub_opts.c
$(blddir_work)/VersionInfo.h: $(srcdir)/VersionInfo.h.in $(blddir_work)/VersionInfo.h: $(srcdir)/VersionInfo.h.in
$(SED_COMMAND) $< > $@ $(SED_COMMAND) $< > $@
......
...@@ -2730,7 +2730,7 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options) ...@@ -2730,7 +2730,7 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
rc = MQTTASYNC_BAD_MQTT_OPTIONS; rc = MQTTASYNC_BAD_MQTT_OPTIONS;
goto exit; goto exit;
} }
if (options->MQTTVersion < MQTTVERSION_5) if (options->MQTTVersion < MQTTVERSION_5 && options->struct_version >= 6)
{ {
if (options->cleanstart != 0 || options->onFailure5 || options->onSuccess5 || if (options->cleanstart != 0 || options->onFailure5 || options->onSuccess5 ||
options->connectProperties || options->willProperties) options->connectProperties || options->willProperties)
...@@ -2742,8 +2742,11 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options) ...@@ -2742,8 +2742,11 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
m->connect.onSuccess = options->onSuccess; m->connect.onSuccess = options->onSuccess;
m->connect.onFailure = options->onFailure; m->connect.onFailure = options->onFailure;
m->connect.onSuccess5 = options->onSuccess5; if (options->struct_version >= 6)
m->connect.onFailure5 = options->onFailure5; {
m->connect.onSuccess5 = options->onSuccess5;
m->connect.onFailure5 = options->onFailure5;
}
m->connect.context = options->context; m->connect.context = options->context;
m->connectTimeout = options->connectTimeout; m->connectTimeout = options->connectTimeout;
...@@ -2834,7 +2837,6 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options) ...@@ -2834,7 +2837,6 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
if (m->c->sslopts->CApath) if (m->c->sslopts->CApath)
free((void*)m->c->sslopts->CApath); free((void*)m->c->sslopts->CApath);
} }
free(m->c->sslopts);
free((void*)m->c->sslopts); free((void*)m->c->sslopts);
m->c->sslopts = NULL; m->c->sslopts = NULL;
} }
...@@ -3321,6 +3323,19 @@ int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen ...@@ -3321,6 +3323,19 @@ int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen
rc = MQTTASYNC_NO_MORE_MSGIDS; rc = MQTTASYNC_NO_MORE_MSGIDS;
else if (m->createOptions && (MQTTAsync_countBufferedMessages(m) >= m->createOptions->maxBufferedMessages)) else if (m->createOptions && (MQTTAsync_countBufferedMessages(m) >= m->createOptions->maxBufferedMessages))
rc = MQTTASYNC_MAX_BUFFERED_MESSAGES; rc = MQTTASYNC_MAX_BUFFERED_MESSAGES;
else if (response)
{
if (m->c->MQTTVersion >= MQTTVERSION_5)
{
if (response->struct_version == 0 || response->onFailure || response->onSuccess)
rc = MQTTASYNC_BAD_MQTT_OPTIONS;
}
else if (m->c->MQTTVersion < MQTTVERSION_5)
{
if (response->struct_version >= 1 && (response->onFailure5 || response->onSuccess5))
rc = MQTTASYNC_BAD_MQTT_OPTIONS;
}
}
if (rc != MQTTASYNC_SUCCESS) if (rc != MQTTASYNC_SUCCESS)
goto exit; goto exit;
......
...@@ -478,7 +478,7 @@ int WebSocket_getch(networkHandles *net, char* c) ...@@ -478,7 +478,7 @@ int WebSocket_getch(networkHandles *net, char* c)
size_t actual_len = 0u; size_t actual_len = 0u;
rc = WebSocket_receiveFrame( net, 1u, &actual_len ); rc = WebSocket_receiveFrame( net, 1u, &actual_len );
if ( rc != TCPSOCKET_COMPLETE ) if ( rc != TCPSOCKET_COMPLETE )
return rc; goto exit;
/* we got a frame, let take off the top of queue */ /* we got a frame, let take off the top of queue */
if ( in_frames->first ) if ( in_frames->first )
...@@ -501,6 +501,7 @@ int WebSocket_getch(networkHandles *net, char* c) ...@@ -501,6 +501,7 @@ int WebSocket_getch(networkHandles *net, char* c)
else else
rc = Socket_getch(net->socket, c); rc = Socket_getch(net->socket, c);
exit:
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
return rc; return rc;
} }
...@@ -543,7 +544,7 @@ char *WebSocket_getdata(networkHandles *net, size_t bytes, size_t* actual_len) ...@@ -543,7 +544,7 @@ char *WebSocket_getdata(networkHandles *net, size_t bytes, size_t* actual_len)
free( last_frame ); free( last_frame );
last_frame = ListDetachHead(in_frames); last_frame = ListDetachHead(in_frames);
} }
return rv; goto exit;
} }
/* no current frame, let's see if there's one in the list */ /* no current frame, let's see if there's one in the list */
...@@ -577,6 +578,7 @@ char *WebSocket_getdata(networkHandles *net, size_t bytes, size_t* actual_len) ...@@ -577,6 +578,7 @@ char *WebSocket_getdata(networkHandles *net, size_t bytes, size_t* actual_len)
else else
rv = WebSocket_getRawSocketData(net, bytes, actual_len); rv = WebSocket_getRawSocketData(net, bytes, actual_len);
exit:
rc = rv != NULL; rc = rv != NULL;
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
return rv; return rv;
......
...@@ -29,15 +29,15 @@ IF (WIN32) ...@@ -29,15 +29,15 @@ IF (WIN32)
ENDIF() ENDIF()
# sample files c # sample files c
ADD_EXECUTABLE(paho_c_pub paho_c_pub.c) ADD_EXECUTABLE(paho_c_pub paho_c_pub.c pubsub_opts.c)
ADD_EXECUTABLE(paho_c_sub paho_c_sub.c) ADD_EXECUTABLE(paho_c_sub paho_c_sub.c pubsub_opts.c)
ADD_EXECUTABLE(paho_cs_pub paho_cs_pub.c) ADD_EXECUTABLE(paho_cs_pub paho_cs_pub.c)
ADD_EXECUTABLE(paho_cs_sub paho_cs_sub.c) ADD_EXECUTABLE(paho_cs_sub paho_cs_sub.c)
TARGET_LINK_LIBRARIES(paho_c_pub paho-mqtt3a) TARGET_LINK_LIBRARIES(paho_c_pub paho-mqtt3as)
TARGET_LINK_LIBRARIES(paho_c_sub paho-mqtt3a) TARGET_LINK_LIBRARIES(paho_c_sub paho-mqtt3as)
TARGET_LINK_LIBRARIES(paho_cs_pub paho-mqtt3c) TARGET_LINK_LIBRARIES(paho_cs_pub paho-mqtt3cs)
TARGET_LINK_LIBRARIES(paho_cs_sub paho-mqtt3c) TARGET_LINK_LIBRARIES(paho_cs_sub paho-mqtt3cs)
ADD_EXECUTABLE(MQTTAsync_subscribe MQTTAsync_subscribe.c) ADD_EXECUTABLE(MQTTAsync_subscribe MQTTAsync_subscribe.c)
ADD_EXECUTABLE(MQTTAsync_publish MQTTAsync_publish.c) ADD_EXECUTABLE(MQTTAsync_publish MQTTAsync_publish.c)
......
This diff is collapsed.
This diff is collapsed.
/*******************************************************************************
* Copyright (c) 2012, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include "MQTTAsync.h"
#include "MQTTClientPersistence.h"
#include "pubsub_opts.h"
#include <string.h>
#include <stdlib.h>
int getopts(int argc, char** argv, struct pubsub_opts* opts)
{
int count = 2;
while (count < argc)
{
if (strcmp(argv[count], "--retained") == 0 || strcmp(argv[count], "-r") == 0)
opts->retained = 1;
else if (strcmp(argv[count], "--verbose") == 0 || strcmp(argv[count], "-v") == 0)
opts->verbose = 1;
else if (strcmp(argv[count], "--qos") == 0 || strcmp(argv[count], "-q") == 0)
{
if (++count < argc)
{
if (strcmp(argv[count], "0") == 0)
opts->qos = 0;
else if (strcmp(argv[count], "1") == 0)
opts->qos = 1;
else if (strcmp(argv[count], "2") == 0)
opts->qos = 2;
else
return 1;
}
else
return 1;
}
else if (strcmp(argv[count], "--connection") == 0 || strcmp(argv[count], "-c") == 0)
{
if (++count < argc)
opts->connection = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--host") == 0 || strcmp(argv[count], "-h") == 0)
{
if (++count < argc)
opts->host = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--port") == 0 || strcmp(argv[count], "-p") == 0)
{
if (++count < argc)
opts->port = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--clientid") == 0 || strcmp(argv[count], "-i") == 0)
{
if (++count < argc)
opts->clientid = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--username") == 0 || strcmp(argv[count], "-u") == 0)
{
if (++count < argc)
opts->username = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--password") == 0 || strcmp(argv[count], "-P") == 0)
{
if (++count < argc)
opts->password = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--maxdatalen") == 0)
{
if (++count < argc)
opts->maxdatalen = atoi(argv[count]);
else
return 1;
}
else if (strcmp(argv[count], "--message-expiry") == 0)
{
if (++count < argc)
opts->message_expiry = atoi(argv[count]);
else
return 1;
}
else if (strcmp(argv[count], "--delimiter") == 0)
{
if (++count < argc)
opts->delimiter = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--keepalive") == 0 || strcmp(argv[count], "-k") == 0)
{
if (++count < argc)
opts->keepalive = atoi(argv[count]);
else
return 1;
}
else if (strcmp(argv[count], "--topic") == 0 || strcmp(argv[count], "-t") == 0)
{
if (++count < argc)
opts->topic = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--will-topic") == 0)
{
if (++count < argc)
opts->will_topic = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--will-payload") == 0)
{
if (++count < argc)
opts->will_payload = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--will-qos") == 0)
{
if (++count < argc)
opts->will_qos = atoi(argv[count]);
else
return 1;
}
else if (strcmp(argv[count], "--will-retain") == 0)
{
if (++count < argc)
opts->will_retain = 1;
else
return 1;
}
else if (strcmp(argv[count], "--insecure") == 0)
{
if (++count < argc)
opts->insecure = 1;
else
return 1;
}
else if (strcmp(argv[count], "--capath") == 0)
{
if (++count < argc)
opts->capath = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--cafile") == 0)
{
if (++count < argc)
opts->cafile = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--cert") == 0)
{
if (++count < argc)
opts->cert = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--key") == 0)
{
if (++count < argc)
opts->key = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--keypass") == 0)
{
if (++count < argc)
opts->keypass = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "--ciphers") == 0)
{
if (++count < argc)
opts->ciphers = argv[count];
else
return 1;
}
else if (strcmp(argv[count], "-V") == 0)
{
if (++count < argc)
{
if (strcmp(argv[count], "mqttv31") == 0 || strcmp(argv[count], "31") == 0)
opts->MQTTVersion = MQTTVERSION_3_1;
else if (strcmp(argv[count], "mqttv311") == 0 || strcmp(argv[count], "311") == 0)
opts->MQTTVersion = MQTTVERSION_3_1_1;
else if (strcmp(argv[count], "mqttv5") == 0 || strcmp(argv[count], "5") == 0)
opts->MQTTVersion = MQTTVERSION_5;
else
return 1;
}
else
return 1;
}
else if (strcmp(argv[count], "--trace") == 0)
{
if (++count < argc)
{
if (strcmp(argv[count], "error") == 0)
opts->tracelevel = MQTTASYNC_TRACE_ERROR;
else if (strcmp(argv[count], "protocol") == 0)
opts->tracelevel = MQTTASYNC_TRACE_PROTOCOL;
else if (strcmp(argv[count], "min") == 0 || strcmp(argv[count], "on") == 0)
opts->tracelevel = MQTTASYNC_TRACE_MINIMUM;
else if (strcmp(argv[count], "max") == 0)
opts->tracelevel = MQTTASYNC_TRACE_MAXIMUM;
else
return 1;
}
else
return 1;
}
else if (strcmp(argv[count], "--user-property") == 0)
{
if (count + 2 < argc)
{
opts->user_property.name = argv[++count];
opts->user_property.value = argv[++count];
}
else
return 1;
}
else
{
printf("Unknown arg %s\n", argv[count]);
return 1;
}
count++;
}
return 0;
}
/*******************************************************************************
* Copyright (c) 2012, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
#if !defined(PUBSUB_OPTS_H)
#define PUBSUB_OPTS_H
#include "MQTTAsync.h"
#include "MQTTClientPersistence.h"
struct pubsub_opts
{
int MQTTVersion;
int tracelevel;
char* topic;
char* clientid;
char* delimiter;
int maxdatalen;
int qos;
int retained;
char* username;
char* password;
char* host;
char* port;
char* connection;
int verbose;
int keepalive;
char* will_topic;
char* will_payload;
int will_qos;
int will_retain;
int insecure;
char* capath;
char* cert;
char* cafile;
char* key;
char* keypass;
char* ciphers;
int message_expiry;
struct {
char *name;
char *value;
} user_property;
};
int getopts(int argc, char** argv, struct pubsub_opts* opts);
#endif
...@@ -84,6 +84,7 @@ struct Options ...@@ -84,6 +84,7 @@ struct Options
char* client_private_key_file; char* client_private_key_file;
int verbose; int verbose;
int test_no; int test_no;
int websockets;
} options = } options =
{ {
"ssl://m2m.eclipse.org:18883", "ssl://m2m.eclipse.org:18883",
...@@ -99,6 +100,7 @@ struct Options ...@@ -99,6 +100,7 @@ struct Options
NULL, NULL,
0, 0,
0, 0,
0,
}; };
...@@ -154,16 +156,18 @@ void getopts(int argc, char** argv) ...@@ -154,16 +156,18 @@ void getopts(int argc, char** argv)
{ {
if (++count < argc) if (++count < argc)
{ {
sprintf(options.connection, "ssl://%s:18883", argv[count]); char* prefix = (options.websockets) ? "wss" : "ssl";
sprintf(options.connection, "%s://%s:18883", prefix, argv[count]);
printf("Setting connection to %s\n", options.connection); printf("Setting connection to %s\n", options.connection);
sprintf(options.mutual_auth_connection, "ssl://%s:18884", argv[count]); sprintf(options.mutual_auth_connection, "%s://%s:18884", prefix, argv[count]);
printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection); printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection);
sprintf(options.nocert_mutual_auth_connection, "ssl://%s:18887", argv[count]); sprintf(options.nocert_mutual_auth_connection, "%s://%s:18887", prefix, argv[count]);
printf("Setting nocert_mutual_auth_connection to %s\n", printf("Setting nocert_mutual_auth_connection to %s\n",
options.nocert_mutual_auth_connection); options.nocert_mutual_auth_connection);
sprintf(options.server_auth_connection, "ssl://%s:18885", argv[count]); sprintf(options.server_auth_connection, "%s://%s:18885", prefix, argv[count]);
printf("Setting server_auth_connection to %s\n", options.server_auth_connection); printf("Setting server_auth_connection to %s\n", options.server_auth_connection);
sprintf(options.anon_connection, "ssl://%s:18886", argv[count]); sprintf(options.anon_connection, "%s://%s:18886", prefix, argv[count]);
printf("Setting anon_connection to %s\n", options.anon_connection); printf("Setting anon_connection to %s\n", options.anon_connection);
} }
else else
...@@ -242,9 +246,13 @@ void getopts(int argc, char** argv) ...@@ -242,9 +246,13 @@ void getopts(int argc, char** argv)
else if (strcmp(argv[count], "--verbose") == 0) else if (strcmp(argv[count], "--verbose") == 0)
{ {
options.verbose = 1; options.verbose = 1;
//TODO
printf("\nSetting verbose on\n"); printf("\nSetting verbose on\n");
} }
else if (strcmp(argv[count], "--ws") == 0)
{
options.websockets = 1;
printf("\nSetting websockets on\n");
}
count++; count++;
} }
#if defined(IOS) #if defined(IOS)
......
...@@ -66,6 +66,7 @@ struct Options ...@@ -66,6 +66,7 @@ struct Options
int verbose; int verbose;
int test_no; int test_no;
int size; int size;
int websockets;
} options = } options =
{ {
"ssl://m2m.eclipse.org:18883", "ssl://m2m.eclipse.org:18883",
...@@ -79,7 +80,8 @@ struct Options ...@@ -79,7 +80,8 @@ struct Options
NULL, NULL,
0, 0,
0, 0,
5000000 5000000,
0,
}; };
typedef struct typedef struct
...@@ -143,21 +145,28 @@ void getopts(int argc, char** argv) ...@@ -143,21 +145,28 @@ void getopts(int argc, char** argv)
{ {
if (++count < argc) if (++count < argc)
{ {
sprintf(options.connection, "ssl://%s:18883", argv[count]); char* prefix = (options.websockets) ? "wss" : "ssl";
sprintf(options.connection, "%s://%s:18883", prefix, argv[count]);
printf("Setting connection to %s\n", options.connection); printf("Setting connection to %s\n", options.connection);
sprintf(options.mutual_auth_connection, "ssl://%s:18884", argv[count]); sprintf(options.mutual_auth_connection, "%s://%s:18884", prefix, argv[count]);
printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection); printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection);
sprintf(options.nocert_mutual_auth_connection, "ssl://%s:18887", argv[count]); sprintf(options.nocert_mutual_auth_connection, "%s://%s:18887", prefix, argv[count]);
printf("Setting nocert_mutual_auth_connection to %s\n", printf("Setting nocert_mutual_auth_connection to %s\n",
options.nocert_mutual_auth_connection); options.nocert_mutual_auth_connection);
sprintf(options.server_auth_connection, "ssl://%s:18885", argv[count]); sprintf(options.server_auth_connection, "%s://%s:18885", prefix, argv[count]);
printf("Setting server_auth_connection to %s\n", options.server_auth_connection); printf("Setting server_auth_connection to %s\n", options.server_auth_connection);
sprintf(options.anon_connection, "ssl://%s:18886", argv[count]); sprintf(options.anon_connection, "%s://%s:18886", prefix, argv[count]);
printf("Setting anon_connection to %s\n", options.anon_connection); printf("Setting anon_connection to %s\n", options.anon_connection);
} }
else else
usage(); usage();
} }
else if (strcmp(argv[count], "--ws") == 0)
{
options.websockets = 1;
printf("\nSetting websockets on\n");
}
count++; count++;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment