test5.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2012, 2020 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v2.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  * https://www.eclipse.org/legal/epl-2.0/
10  * and the Eclipse Distribution License is available at
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  * Allan Stockdill-Mander - initial API and implementation and/or initial documentation
15  * Ian Craggs - fix Windows includes
16  *******************************************************************************/
17 
23 #include "MQTTAsync.h"
24 #include <string.h>
25 #include <stdlib.h>
26 #include "Thread.h"
27 
28 #if defined(_WINDOWS)
29 #include <windows.h>
30 #include <openssl/applink.c>
31 #define MAXHOSTNAMELEN 256
32 #define snprintf _snprintf
33 #else
34 #include <sys/time.h>
35 #include <sys/socket.h>
36 #include <unistd.h>
37 #include <errno.h>
38 #endif
39 
40 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
41 
42 void usage(void)
43 {
44  printf("Options:\n");
45  printf("\t--test_no <test_no> - Run test number <test_no>\n");
46  printf("\t--hostname <hostname> - Connect to <hostname> for tests\n");
47  printf("\t--client_key <key_file> - Use <key_file> as the client certificate for SSL authentication\n");
48  printf("\t--client_key_pass <password> - Use <password> to access the private key in the client certificate\n");
49  printf("\t--server_key <key_file> - Use <key_file> as the trusted certificate for server\n");
50  printf("\t--verbose - Enable verbose output \n");
51  printf("\t--help - This help output\n");
52  exit(EXIT_FAILURE);
53 }
54 
55 struct Options
56 {
57  char connection[100];
58  char mutual_auth_connection[100];
60  char server_auth_connection[100];
61  char anon_connection[100];
62  char psk_connection[100];
63  char* client_key_file;
64  char* client_key_pass;
65  char* server_key_file;
67  char* capath;
68  int verbose;
69  int test_no;
70  int size;
71  int websockets;
74 } options =
75 {
76  "ssl://m2m.eclipse.org:18883",
77  "ssl://m2m.eclipse.org:18884",
78  "ssl://m2m.eclipse.org:18887",
79  "ssl://m2m.eclipse.org:18885",
80  "ssl://m2m.eclipse.org:18886",
81  "ssl://m2m.eclipse.org:18888",
82  NULL, // "../../../test/ssl/client.pem",
83  NULL,
84  NULL, // "../../../test/ssl/test-root-ca.crt",
85  NULL, // "../../../test/ssl/capath",
86  NULL,
87  0,
88  0,
89  5000000,
90  0,
91  3,
92  18883,
93 };
94 
95 typedef struct
96 {
98  char clientid[24];
99  char topic[100];
100  int maxmsgs;
101  int rcvdmsgs[3];
102  int sentmsgs[3];
106 
107 #define AsyncTestClient_initializer {NULL, "\0", "\0", 0, {0, 0, 0}, {0, 0, 0}, 0, 0}
108 
109 void getopts(int argc, char** argv)
110 {
111  int count = 1;
112 
113  while (count < argc)
114  {
115  if (strcmp(argv[count], "--help") == 0)
116  {
117  usage();
118  }
119  else if (strcmp(argv[count], "--test_no") == 0)
120  {
121  if (++count < argc)
122  options.test_no = atoi(argv[count]);
123  else
124  usage();
125  }
126  else if (strcmp(argv[count], "--client_key") == 0)
127  {
128  if (++count < argc)
129  options.client_key_file = argv[count];
130  else
131  usage();
132  }
133  else if (strcmp(argv[count], "--client_key_pass") == 0)
134  {
135  if (++count < argc)
136  options.client_key_pass = argv[count];
137  else
138  usage();
139  }
140  else if (strcmp(argv[count], "--server_key") == 0)
141  {
142  if (++count < argc)
143  options.server_key_file = argv[count];
144  else
145  usage();
146  }
147  else if (strcmp(argv[count], "--capath") == 0)
148  {
149  if (++count < argc)
150  options.capath = argv[count];
151  else
152  usage();
153  }
154  else if (strcmp(argv[count], "--verbose") == 0)
155  {
156  options.verbose = 1;
157  printf("\nSetting verbose on\n");
158  }
159  else if (strcmp(argv[count], "--hostname") == 0)
160  {
161  if (++count < argc)
162  {
163  char* prefix = (options.websockets) ? "wss" : "ssl";
164 
165  sprintf(options.connection, "%s://%s:%d", prefix, argv[count],
167  printf("Setting connection to %s\n", options.connection);
168  sprintf(options.mutual_auth_connection, "%s://%s:%d", prefix, argv[count],
169  options.start_port+1);
170  printf("Setting mutual_auth_connection to %s\n", options.mutual_auth_connection);
171  sprintf(options.nocert_mutual_auth_connection, "%s://%s:%d", prefix,
172  argv[count], options.start_port+4);
173  printf("Setting nocert_mutual_auth_connection to %s\n",
175  sprintf(options.server_auth_connection, "%s://%s:%d", prefix, argv[count],
176  options.start_port+2);
177  printf("Setting server_auth_connection to %s\n", options.server_auth_connection);
178  sprintf(options.anon_connection, "%s://%s:%d", prefix, argv[count],
179  options.start_port+3);
180  printf("Setting anon_connection to %s\n", options.anon_connection);
181  sprintf(options.psk_connection, "%s://%s:%d", prefix, argv[count],
182  options.start_port+5);
183  printf("Setting psk_connection to %s\n", options.psk_connection);
184  }
185  else
186  usage();
187  }
188  else if (strcmp(argv[count], "--ws") == 0)
189  {
190  options.websockets = 1;
191  printf("\nSetting websockets on\n");
192  }
193  else if (strcmp(argv[count], "--size") == 0)
194  {
195  if (++count < argc)
196  {
197  options.size = atoi(argv[count]);
198  printf("\nSetting size to %d\n", options.size);
199  }else
200  usage();
201  }
202  else if (strcmp(argv[count], "--port") == 0)
203  {
204  if (++count < argc)
205  {
206  options.start_port = atoi(argv[count]);
207  printf("\nSetting start_port to %d\n", options.start_port);
208  }else
209  usage();
210  }
211  else if (strcmp(argv[count], "--count") == 0)
212  {
213  if (++count < argc)
214  {
215  options.message_count = atoi(argv[count]);
216  printf("\nSetting message count to %d\n", options.message_count);
217  }else
218  usage();
219  }
220  else
221  printf("Unrecognized option %s\n", argv[count]);
222  count++;
223  }
224 }
225 
226 
227 #define LOGA_DEBUG 0
228 #define LOGA_INFO 1
229 #include <stdarg.h>
230 #include <time.h>
231 #include <sys/timeb.h>
232 void MyLog(int LOGA_level, char* format, ...)
233 {
234  static char msg_buf[256];
235  va_list args;
236 #if defined(_WIN32) || defined(_WINDOWS)
237  struct timeb ts;
238 #else
239  struct timeval ts;
240 #endif
241  struct tm timeinfo;
242 
243  if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
244  return;
245 
246 #if defined(_WIN32) || defined(_WINDOWS)
247  ftime(&ts);
248  localtime_s(&timeinfo, &ts.time);
249 #else
250  gettimeofday(&ts, NULL);
251  localtime_r(&ts.tv_sec, &timeinfo);
252 #endif
253  strftime(msg_buf, 80, "%Y%m%d %H%M%S", &timeinfo);
254 
255 #if defined(_WIN32) || defined(_WINDOWS)
256  sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
257 #else
258  sprintf(&msg_buf[strlen(msg_buf)], ".%.3lu ", ts.tv_usec / 1000);
259 #endif
260 
261  va_start(args, format);
262  vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
263  va_end(args);
264 
265  printf("%s\n", msg_buf);
266  fflush(stdout);
267 }
268 
269 
270 #if defined(_WIN32) || defined(_WINDOWS)
271 #define mqsleep(A) Sleep(1000*A)
272 #define START_TIME_TYPE DWORD
273 static DWORD start_time = 0;
275 {
276  return GetTickCount();
277 }
278 #elif defined(AIX)
279 #define mqsleep sleep
280 #define START_TIME_TYPE struct timespec
282 {
283  static struct timespec start;
284  clock_gettime(CLOCK_REALTIME, &start);
285  return start;
286 }
287 #else
288 #define mqsleep sleep
289 #define START_TIME_TYPE struct timeval
290 /* TODO - unused - remove? static struct timeval start_time; */
292 {
293  struct timeval start_time;
294  gettimeofday(&start_time, NULL);
295  return start_time;
296 }
297 #endif
298 
299 #if defined(_WIN32)
300 long elapsed(START_TIME_TYPE start_time)
301 {
302  return GetTickCount() - start_time;
303 }
304 #elif defined(AIX)
305 #define assert(a)
306 long elapsed(struct timespec start)
307 {
308  struct timespec now, res;
309 
310  clock_gettime(CLOCK_REALTIME, &now);
311  ntimersub(now, start, res);
312  return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
313 }
314 #else
315 long elapsed(START_TIME_TYPE start_time)
316 {
317  struct timeval now, res;
318 
319  gettimeofday(&now, NULL);
320  timersub(&now, &start_time, &res);
321  return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
322 }
323 #endif
324 
325 #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
326 #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
327 
328 #define MAXMSGS 30;
329 
330 int tests = 0;
331 int failures = 0;
332 FILE* xml;
334 char output[3000];
336 
337 
339 {
340  long duration = elapsed(global_start_time);
341 
342  fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
343  if (cur_output != output)
344  {
345  fprintf(xml, "%s", output);
346  cur_output = output;
347  }
348  fprintf(xml, "</testcase>\n");
349 }
350 
351 void myassert(char* filename, int lineno, char* description, int value,
352  char* format, ...)
353 {
354  ++tests;
355  if (!value)
356  {
357  va_list args;
358 
359  ++failures;
360  printf("Assertion failed, file %s, line %d, description: %s", filename,
361  lineno, description);
362 
363  va_start(args, format);
364  vprintf(format, args);
365  va_end(args);
366 
367  cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
368  description, filename, lineno);
369  }
370  else
372  "Assertion succeeded, file %s, line %d, description: %s",
373  filename, lineno, description);
374 }
375 
376 /*********************************************************************
377 
378  Test: multi-threaded client using callbacks
379 
380  *********************************************************************/
381 volatile int multiThread_arrivedcount = 0;
384 
386 {
388 }
389 
390 int multiThread_messageArrived(void* context, char* topicName, int topicLen,
392 {
394  MyLog(LOGA_DEBUG, "Callback: %d message received on topic %s is %.*s.",
395  multiThread_arrivedcount, topicName, m->payloadlen,
396  (char*) (m->payload));
397  if (multiThread_pubmsg.payloadlen != m->payloadlen || memcmp(m->payload,
398  multiThread_pubmsg.payload, m->payloadlen) != 0)
399  {
400  failures++;
401  MyLog(LOGA_INFO, "Error: wrong data received lengths %d %d\n",
402  multiThread_pubmsg.payloadlen, m->payloadlen);
403  }
404  MQTTAsync_free(topicName);
406  return 1;
407 }
408 
410 {
412  int i = 0;
413  int iterations = 50;
414  int rc = 0;
415  int wait_seconds = 0;
416 
419 
420  MyLog(LOGA_DEBUG, "%d messages at QoS %d", iterations, qos);
421  multiThread_pubmsg.payload
422  = "a much longer message that we can shorten to the extent that we need to";
423  multiThread_pubmsg.payloadlen = 27;
424  multiThread_pubmsg.qos = qos;
425  multiThread_pubmsg.retained = 0;
426 
427  for (i = 1; i <= iterations; ++i)
428  {
429  if (i % 10 == 0)
430  rc = MQTTAsync_send(c, test_topic, multiThread_pubmsg.payloadlen,
431  multiThread_pubmsg.payload, multiThread_pubmsg.qos,
432  multiThread_pubmsg.retained, NULL);
433  else
434  rc = MQTTAsync_sendMessage(c, test_topic, &multiThread_pubmsg,
435  &ropts);
436  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
437 
438 #if defined(_WIN32)
439  Sleep(100);
440 #else
441  usleep(100000L);
442 #endif
443 
444  wait_seconds = 10;
445  while ((multiThread_arrivedcount < i) && (wait_seconds-- > 0))
446  {
447  MyLog(LOGA_DEBUG, "Arrived %d count %d", multiThread_arrivedcount,
448  i);
449 #if defined(_WIN32)
450  Sleep(1000);
451 #else
452  usleep(1000000L);
453 #endif
454  }
455  assert("Message Arrived", wait_seconds > 0,
456  "Time out waiting for message %d\n", i );
457  }
458  if (qos > 0)
459  {
460  /* MQ Telemetry can send a message to a subscriber before the server has
461  completed the QoS 2 handshake with the publisher. For QoS 1 and 2,
462  allow time for the final delivery complete callback before checking
463  that all expected callbacks have been made */
464  wait_seconds = 10;
465  while ((multiThread_deliveryCompleted < iterations) && (wait_seconds--
466  > 0))
467  {
468  MyLog(LOGA_DEBUG, "Delivery Completed %d count %d",
470 #if defined(_WIN32)
471  Sleep(1000);
472 #else
473  usleep(1000000L);
474 #endif
475  }
476  assert("All Deliveries Complete", wait_seconds > 0,
477  "Number of deliveryCompleted callbacks was %d\n",
479  }
480 }
481 
482 /*********************************************************************
483 
484  Async Callbacks - generic callbacks for send/receive tests
485 
486  *********************************************************************/
487 
488 /*static mutex_type client_mutex = NULL;
489 static pthread_mutex_t client_mutex_store = PTHREAD_MUTEX_INITIALIZER;
490 static mutex_type client_mutex = &client_mutex_store;*/
491 
493 {
494  //int rc;
495 
496  AsyncTestClient* tc = (AsyncTestClient*) context;
497  MyLog(LOGA_DEBUG, "In asyncTestOnDisconnect callback, %s", tc->clientid);
498  //rc = Thread_lock_mutex(client_mutex);
499  tc->testFinished = 1;
500  //rc = Thread_unlock_mutex(client_mutex);
501 }
502 
504 {
505  AsyncTestClient* tc = (AsyncTestClient*) context;
506  //int rc;
507  int qos = response->alt.pub.message.qos;
508  MyLog(LOGA_DEBUG, "In asyncTestOnSend callback, %s", tc->clientid);
509  //rc = Thread_lock_mutex(client_mutex);
510  tc->sentmsgs[qos]++;
511  //rc = Thread_unlock_mutex(client_mutex);
512 }
513 
515 {
516  AsyncTestClient* tc = (AsyncTestClient*) context;
517  MyLog(LOGA_DEBUG, "In asyncTestOnSubscribeFailure callback, %s",
518  tc->clientid);
519 
520  assert("There should be no failures in this test. ", 0, "asyncTestOnSubscribeFailure callback was called\n", 0);
521 }
522 
524 {
525  AsyncTestClient* tc = (AsyncTestClient*) context;
527  int rc;
528 
529  MyLog(LOGA_DEBUG, "In asyncTestOnUnsubscribe callback, %s", tc->clientid);
531  opts.context = tc;
532 
533  rc = MQTTAsync_disconnect(tc->client, &opts);
534 }
535 
537 {
538  AsyncTestClient* tc = (AsyncTestClient*) context;
539  int rc, i;
540  MyLog(LOGA_DEBUG, "In asyncTestOnSubscribe callback, %s", tc->clientid);
541  //rc = Thread_lock_mutex(client_mutex);
542  tc->subscribed = 1;
543  //rc = Thread_unlock_mutex(client_mutex);
544  for (i = 0; i < 3; i++)
545  {
547 
548  pubmsg.payload
549  = "a much longer message that we can shorten to the extent that we need to payload up to 11";
550  pubmsg.payloadlen = 11;
551  pubmsg.qos = i;
552  pubmsg.retained = 0;
553 
555  //opts.onSuccess = asyncTestOnSend;
556  opts.context = &tc;
557 
558  rc = MQTTAsync_send(tc->client, tc->topic, pubmsg.payloadlen,
559  pubmsg.payload, pubmsg.qos, pubmsg.retained, &opts);
560  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
561  tc->sentmsgs[i]++;
562  MyLog(LOGA_DEBUG, "Maxmsgs %d", tc->maxmsgs);
563  }
564 }
565 
566 int asyncTestMessageArrived(void* context, char* topicName, int topicLen,
568 {
569  AsyncTestClient* tc = (AsyncTestClient*) context;
570  int rc;
571  //rc = Thread_lock_mutex(client_mutex);
572  tc->rcvdmsgs[m->qos]++;
573 
574  //printf("Received messages: %d\n", tc->rcvdmsgs[m->qos]);
575 
577  "In asyncTestMessageArrived callback, %s total to exit %d, total received %d,%d,%d",
578  tc->clientid, (tc->maxmsgs * 3), tc->rcvdmsgs[0], tc->rcvdmsgs[1],
579  tc->rcvdmsgs[2]);
580 
581  if (tc->sentmsgs[m->qos] < tc->maxmsgs)
582  {
584 
585  //opts.onSuccess = asyncTestOnSend;
586  opts.context = tc;
587 
589  pubmsg.payload
590  = "a much longer message that we can shorten to the extent that we need to payload up to 11";
591  pubmsg.payloadlen = 11;
592  pubmsg.qos = m->qos;
593  pubmsg.retained = 0;
594 
595  rc = MQTTAsync_send(tc->client, tc->topic, pubmsg.payloadlen,
596  pubmsg.payload, pubmsg.qos, pubmsg.retained, &opts);
597  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d messages sent %d,%d,%d", rc);
598  MyLog(LOGA_DEBUG, "Messages sent %d,%d,%d", tc->sentmsgs[0],
599  tc->sentmsgs[1], tc->sentmsgs[2]);
600  tc->sentmsgs[m->qos]++;
601  }
602  if ((tc->rcvdmsgs[0] + tc->rcvdmsgs[1] + tc->rcvdmsgs[2]) == (tc->maxmsgs* 3))
603  {
604  MyLog(LOGA_DEBUG, "Ready to unsubscribe");
606 
608  opts.context = tc;
609  rc = MQTTAsync_unsubscribe(tc->client, tc->topic, &opts);
610  assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
611  }
612  //rc = Thread_unlock_mutex(client_mutex);
613  MyLog(LOGA_DEBUG, "Leaving asyncTestMessageArrived callback");
615  MQTTAsync_free(topicName);
616  return 1;
617 }
618 
620 {
621 
622 }
623 
625 {
626  AsyncTestClient* tc = (AsyncTestClient*) context;
627  int subsqos = 2;
628  int rc;
629  MyLog(LOGA_DEBUG, "In asyncTestOnConnect callback, %s", tc->clientid);
630 
634  opts.context = tc;
635 
636  rc = MQTTAsync_subscribe(tc->client, tc->topic, subsqos, &opts);
637  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
638 }
639 
640 /*********************************************************************
641 
642  Test1: SSL connection to non SSL MQTT server
643 
644  *********************************************************************/
645 
647 
649 
651 {
652  MyLog(LOGA_DEBUG, "In connect onFailure callback, context %p", context);
653 
655  test1Finished = 1;
656 }
657 
659 {
660 
661  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p\n", context);
662 
663  assert("Connect should not succeed", 0, "connect success callback was called", 0);
664 
665  test1Finished = 1;
666 }
667 
668 int test1(struct Options options)
669 {
670  char* testname = "test1";
671  int subsqos = 2;
672  MQTTAsync c;
676  int rc = 0;
677  char* test_topic = "C client SSL test1";
678  int count = 0;
679 
680  test1Finished = 0;
681  failures = 0;
682  MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server");
683  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
685 
686  rc = MQTTAsync_create(&c, "rubbish://wrong", "test1", MQTTCLIENT_PERSISTENCE_DEFAULT,
687  NULL);
688  assert("bad rc from create", rc == MQTTASYNC_BAD_PROTOCOL, "rc was %d \n", rc);
689 
691  NULL);
692  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
693  if (rc != MQTTASYNC_SUCCESS)
694  {
695  MQTTAsync_destroy(&c);
696  goto exit;
697  }
698 
699  opts.keepAliveInterval = 20;
700  opts.cleansession = 1;
701  opts.username = "testuser";
702  opts.password = "testpassword";
703 
704  opts.will = &wopts;
705  opts.will->message = "will message";
706  opts.will->qos = 1;
707  opts.will->retained = 0;
708  opts.will->topicName = "will topic";
709  opts.will = NULL;
710  opts.onSuccess = test1OnConnect;
711  opts.onFailure = test1OnFailure;
712  opts.context = c;
713 
714  rc = MQTTAsync_connect(c, &opts);
715  assert("Bad rc from connect", rc == MQTTASYNC_NULL_PARAMETER, "rc was %d ", rc);
716 
717  opts.ssl = &sslopts;
718  opts.ssl->enableServerCertAuth = 0;
719 
720  MyLog(LOGA_DEBUG, "Connecting");
721  rc = MQTTAsync_connect(c, &opts);
722  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d ", rc);
723  if (rc != MQTTASYNC_SUCCESS)
724  {
725  failures++;
726  goto exit;
727  }
728 
729  /* wait for success or failure callback */
730  while (!test1Finished && ++count < 10000)
731 #if defined(_WIN32)
732  Sleep(100);
733 #else
734  usleep(10000L);
735 #endif
736 
737  exit: MQTTAsync_destroy(&c);
738  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
739  (failures == 0) ? "passed" : "failed", testname, tests, failures);
741  return failures;
742 }
743 
744 /*********************************************************************
745 
746  Test2a: Mutual SSL Authentication - Certificates in place on client and server
747 
748  *********************************************************************/
749 
751 {
752  AsyncTestClient* client = (AsyncTestClient*) context;
753  MyLog(LOGA_DEBUG, "In test2aOnConnectFailure callback, %s",
754  client->clientid);
755 
756  assert("There should be no failures in this test. ", 0, "test2aOnConnectFailure callback was called\n", 0);
757  client->testFinished = 1;
758 }
759 
761 {
762  AsyncTestClient* client = (AsyncTestClient*) context;
763  MyLog(LOGA_DEBUG, "In test2aOnPublishFailure callback, %s",
764  client->clientid);
765 
766  assert("There should be no failures in this test. ", 0, "test2aOnPublishFailure callback was called\n", 0);
767 }
768 
769 int test2a(struct Options options)
770 {
771  char* testname = "test2a";
772 
773  AsyncTestClient tc =
775  MQTTAsync c;
779  int rc = 0;
780 
781  failures = 0;
782  MyLog(LOGA_INFO, "Starting test 2a - Mutual SSL authentication");
783  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
785 
787  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
788  if (rc != MQTTASYNC_SUCCESS)
789  goto exit;
790 
791  tc.client = c;
792  sprintf(tc.clientid, "%s", testname);
793  sprintf(tc.topic, "C client SSL test2a");
794  tc.maxmsgs = MAXMSGS;
795  //tc.rcvdmsgs = 0;
796  tc.subscribed = 0;
797  tc.testFinished = 0;
798 
799  opts.keepAliveInterval = 20;
800  opts.cleansession = 1;
801  opts.username = "testuser";
802  opts.password = "testpassword";
803 
804  opts.will = &wopts;
805  opts.will->message = "will message";
806  opts.will->qos = 1;
807  opts.will->retained = 0;
808  opts.will->topicName = "will topic";
809  opts.will = NULL;
812  opts.context = &tc;
813 
814  opts.ssl = &sslopts;
815  if (options.server_key_file != NULL)
816  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
817  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
818  if (options.client_key_pass != NULL)
819  opts.ssl->privateKeyPassword = options.client_key_pass;
820  //opts.ssl->enabledCipherSuites = "DEFAULT";
821  //opts.ssl->enabledServerCertAuth = 1;
822  opts.ssl->verify = 1;
823  MyLog(LOGA_DEBUG, "enableServerCertAuth %d\n", opts.ssl->enableServerCertAuth);
824  MyLog(LOGA_DEBUG, "verify %d\n", opts.ssl->verify);
825 
828  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
829 
830  MyLog(LOGA_DEBUG, "Connecting");
831  rc = MQTTAsync_connect(c, &opts);
832  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
833  if (rc != MQTTASYNC_SUCCESS)
834  goto exit;
835 
836  while (!tc.subscribed && !tc.testFinished)
837 #if defined(_WIN32)
838  Sleep(100);
839 #else
840  usleep(10000L);
841 #endif
842 
843  if (tc.testFinished)
844  goto exit;
845 
846  while (!tc.testFinished)
847 #if defined(_WIN32)
848  Sleep(100);
849 #else
850  usleep(10000L);
851 #endif
852 
853  MyLog(LOGA_DEBUG, "Stopping");
854 
855  exit: MQTTAsync_destroy(&c);
856  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
857  (failures == 0) ? "passed" : "failed", testname, tests, failures);
859  return failures;
860 }
861 
862 /*********************************************************************
863 
864  Test2b: Mutual SSL Authentication - Server does not have Client cert
865 
866  *********************************************************************/
867 
869 
871 {
872  MyLog(LOGA_DEBUG, "In test2bOnConnectFailure callback, context %p", context);
873 
874  assert("This test should call test2bOnConnectFailure. ", 1, "test2bOnConnectFailure callback was called\n", 1);
875  test2bFinished = 1;
876 }
877 
879 {
880  MyLog(LOGA_DEBUG, "In test2bOnConnectFailure callback, context %p", context);
881 
882  assert("This connect should not succeed. ", 0, "test2bOnConnect callback was called\n", 0);
883  test2bFinished = 1;
884 }
885 
886 int test2b(struct Options options)
887 {
888  char* testname = "test2b";
889  int subsqos = 2;
890  MQTTAsync c;
894  int rc = 0;
895  int count = 0;
896 
897  test2bFinished = 0;
898  failures = 0;
900  "Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert");
901  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
903 
905  "test2b", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
906  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
907  if (rc != MQTTASYNC_SUCCESS)
908  {
909  MQTTAsync_destroy(&c);
910  goto exit;
911  }
912 
913  opts.keepAliveInterval = 20;
914  opts.cleansession = 1;
915  opts.username = "testuser";
916  opts.password = "testpassword";
917 
918  opts.will = &wopts;
919  opts.will->message = "will message";
920  opts.will->qos = 1;
921  opts.will->retained = 0;
922  opts.will->topicName = "will topic";
923  opts.will = NULL;
924  opts.onSuccess = test2bOnConnect;
926  opts.context = c;
927 
928  opts.ssl = &sslopts;
929  if (options.server_key_file != NULL)
930  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
931  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
932  if (options.client_key_pass != NULL)
933  opts.ssl->privateKeyPassword = options.client_key_pass;
934  //opts.ssl->enabledCipherSuites = "DEFAULT";
935  //opts.ssl->enabledServerCertAuth = 0;
936 
937  MyLog(LOGA_DEBUG, "Connecting");
938  rc = MQTTAsync_connect(c, &opts);
939  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
940  if (rc != MQTTASYNC_SUCCESS)
941  goto exit;
942 
943  while (!test2bFinished && ++count < 10000)
944 #if defined(_WIN32)
945  Sleep(100);
946 #else
947  usleep(10000L);
948 #endif
949 
950  exit: MQTTAsync_destroy(&c);
951  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
952  (failures == 0) ? "passed" : "failed", testname, tests, failures);
954  return failures;
955 }
956 
957 /*********************************************************************
958 
959  Test2c: Mutual SSL Authentication - Client does not have Server cert
960 
961  *********************************************************************/
962 
964 
966 {
967  MyLog(LOGA_DEBUG, "In test2cOnConnectFailure callback, context %p", context);
968 
969  assert("This test should call test2cOnConnectFailure. ", 1, "test2cOnConnectFailure callback was called\n", 0);
970  test2cFinished = 1;
971 }
972 
974 {
975  MyLog(LOGA_DEBUG, "In test2cOnConnect callback, context %p", context);
976 
977  assert("This connect should not succeed. ", 0, "test2cOnConnect callback was called\n", 0);
978  test2cFinished = 1;
979 }
980 
981 int test2c(struct Options options)
982 {
983  char* testname = "test2c";
984  int subsqos = 2;
985  MQTTAsync c;
989  int rc = 0;
990  char* test_topic = "C client test2c";
991  int count = 0;
992 
993  failures = 0;
994  MyLog(
995  LOGA_INFO,
996  "Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert");
997  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
999 
1001  "test2c", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1002  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1003  if (rc != MQTTASYNC_SUCCESS)
1004  {
1005  MQTTAsync_destroy(&c);
1006  goto exit;
1007  }
1008 
1009  opts.keepAliveInterval = 20;
1010  opts.cleansession = 1;
1011  opts.username = "testuser";
1012  opts.password = "testpassword";
1013 
1014  opts.will = &wopts;
1015  opts.will->message = "will message";
1016  opts.will->qos = 1;
1017  opts.will->retained = 0;
1018  opts.will->topicName = "will topic";
1019  opts.will = NULL;
1020  opts.onSuccess = test2cOnConnect;
1022  opts.context = c;
1023 
1024  opts.ssl = &sslopts;
1025  //if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
1026  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1027  if (options.client_key_pass != NULL)
1028  opts.ssl->privateKeyPassword = options.client_key_pass;
1029  //opts.ssl->enabledCipherSuites = "DEFAULT";
1030  //opts.ssl->enabledServerCertAuth = 0;
1031 
1032  MyLog(LOGA_DEBUG, "Connecting");
1033  rc = MQTTAsync_connect(c, &opts);
1034  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1035  if (rc != MQTTASYNC_SUCCESS)
1036  {
1037  failures++;
1038  goto exit;
1039  }
1040 
1041  while (!test2cFinished && ++count < 10000)
1042 #if defined(_WIN32)
1043  Sleep(100);
1044 #else
1045  usleep(10000L);
1046 #endif
1047 
1048  exit: MQTTAsync_destroy(&c);
1049  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1050  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1052  return failures;
1053 }
1054 
1055 
1056 /*********************************************************************
1057 
1058  Test2d: Mutual SSL Authentication - client has no certs
1059 
1060  *********************************************************************/
1061 
1063 
1065 {
1066  MyLog(LOGA_DEBUG, "In test2dOnConnectFailure callback, context %p", context);
1067 
1068  assert("This test should call test2dOnConnectFailure. ", 1, "test2dOnConnectFailure callback was called\n", 0);
1069  test2dFinished = 1;
1070 }
1071 
1073 {
1074  MyLog(LOGA_DEBUG, "In test2dOnConnect callback, context %p", context);
1075 
1076  assert("This connect should not succeed. ", 0, "test2dOnConnect callback was called\n", 0);
1077  test2dFinished = 1;
1078 }
1079 
1081 {
1082  char* testname = "test2d";
1083  int subsqos = 2;
1084  MQTTAsync c;
1088  int rc = 0;
1089  char* test_topic = "C client test2d";
1090  int count = 0;
1091  unsigned int iteration = 0;
1092 
1093  failures = 0;
1094  MyLog(
1095  LOGA_INFO,
1096  "Starting test 2d - connection to SSL MQTT server, server auth enabled but unknown cert");
1097  fprintf(xml, "<testcase classname=\"test2d\" name=\"%s\"", testname);
1099 
1100  // As reported in https://github.com/eclipse/paho.mqtt.c/issues/190
1101  // there is/was some race condition, which caused _sometimes_ that the library failed to detect,
1102  // that the connect attempt has already failed.
1103  // Therefore we need to test this several times!
1104  for (iteration = 0; !failures && (iteration < 20) ; iteration++)
1105  {
1106  count = 0;
1108 
1109  rc = MQTTAsync_create(&c, options.mutual_auth_connection,
1110  "test2d", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1111  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1112 
1113  if (rc != MQTTASYNC_SUCCESS)
1114  {
1115  MQTTAsync_destroy(&c);
1116  failures++;
1117  break;
1118  }
1119 
1120  opts.keepAliveInterval = 60;
1121  opts.cleansession = 1;
1122 
1123  opts.will = &wopts;
1124  opts.will->message = "will message";
1125  opts.will->qos = 1;
1126  opts.will->retained = 0;
1127  opts.will->topicName = "will topic";
1128  opts.will = NULL;
1129  opts.onSuccess = test2dOnConnect;
1131  opts.context = c;
1132 
1133  opts.ssl = &sslopts;
1134  if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
1135  opts.ssl->keyStore = NULL; /*file of certificate for client to present to server - In this test the client has no certificate! */
1136 
1137  test2dFinished = 0;
1138  MyLog(LOGA_DEBUG, "Connecting");
1139  rc = MQTTAsync_connect(c, &opts);
1140  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1141  if (rc != MQTTASYNC_SUCCESS)
1142  {
1143  failures++;
1144  MyLog(LOGA_INFO, "Failed in iteration %d\n",iteration);
1145  MQTTAsync_destroy(&c);
1146  break;
1147  }
1148 #define TEST2D_COUNT 1000
1149  while (!test2dFinished && ++count < TEST2D_COUNT)
1150  {
1151 #if defined(_WIN32)
1152  Sleep(100);
1153 #else
1154  usleep(10000L);
1155 #endif
1156  }
1157  if (!test2dFinished && count >= TEST2D_COUNT)
1158  {
1159  MyLog(LOGA_INFO, "Failed in iteration %d\n",iteration);
1160  failures++;
1161  }
1162  MQTTAsync_destroy(&c);
1163  }
1164  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1165  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1167  return failures;
1168 }
1169 
1170 /*********************************************************************
1171 
1172  Test2e: Mutual SSL Authentication using serverURIs
1173 
1174  *********************************************************************/
1175 
1177 {
1178  AsyncTestClient* client = (AsyncTestClient*) context;
1179  MyLog(LOGA_DEBUG, "In test2eOnConnectFailure callback, %s",
1180  client->clientid);
1181 
1182  assert("There should be no failures in this test. ", 0, "test2eOnConnectFailure callback was called\n", 0);
1183  client->testFinished = 1;
1184 }
1185 
1187 {
1188  AsyncTestClient* client = (AsyncTestClient*) context;
1189  MyLog(LOGA_DEBUG, "In test2eOnPublishFailure callback, %s",
1190  client->clientid);
1191 
1192  assert("There should be no failures in this test. ", 0, "test2eOnPublishFailure callback was called\n", 0);
1193 }
1194 
1196 {
1197  char* testname = "test2e";
1198 
1199  AsyncTestClient tc =
1201  MQTTAsync c;
1205  char* uris[2] = {"rubbish", options.mutual_auth_connection};
1206  int rc = 0;
1207 
1208  failures = 0;
1209  MyLog(LOGA_INFO, "Starting test 2e - Mutual SSL authentication with serverURIs");
1210  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1212 
1213  rc = MQTTAsync_create(&c, "none", "test2e", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
1214  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1215  if (rc != MQTTASYNC_SUCCESS)
1216  goto exit;
1217 
1218  tc.client = c;
1219  sprintf(tc.clientid, "%s", testname);
1220  sprintf(tc.topic, "C client SSL test2e");
1221  tc.maxmsgs = MAXMSGS;
1222  //tc.rcvdmsgs = 0;
1223  tc.subscribed = 0;
1224  tc.testFinished = 0;
1225 
1226  opts.keepAliveInterval = 20;
1227  opts.cleansession = 1;
1228  opts.username = "testuser";
1229  opts.password = "testpassword";
1230 
1231  opts.will = &wopts;
1232  opts.will->message = "will message";
1233  opts.will->qos = 1;
1234  opts.will->retained = 0;
1235  opts.will->topicName = "will topic";
1236  opts.will = NULL;
1239  opts.context = &tc;
1240  opts.serverURIs = uris;
1241  opts.serverURIcount = 2;
1242 
1243  opts.ssl = &sslopts;
1244  if (options.server_key_file != NULL)
1245  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
1246  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1247  if (options.client_key_pass != NULL)
1248  opts.ssl->privateKeyPassword = options.client_key_pass;
1249  //opts.ssl->enabledCipherSuites = "DEFAULT";
1250  //opts.ssl->enabledServerCertAuth = 1;
1251  opts.ssl->verify = 1;
1252  MyLog(LOGA_DEBUG, "enableServerCertAuth %d\n", opts.ssl->enableServerCertAuth);
1253  MyLog(LOGA_DEBUG, "verify %d\n", opts.ssl->verify);
1254 
1257  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1258 
1259  MyLog(LOGA_DEBUG, "Connecting");
1260  rc = MQTTAsync_connect(c, &opts);
1261  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1262  if (rc != MQTTASYNC_SUCCESS)
1263  goto exit;
1264 
1265  while (!tc.subscribed && !tc.testFinished)
1266 #if defined(_WIN32)
1267  Sleep(100);
1268 #else
1269  usleep(10000L);
1270 #endif
1271 
1272  if (tc.testFinished)
1273  goto exit;
1274 
1275  while (!tc.testFinished)
1276 #if defined(_WIN32)
1277  Sleep(100);
1278 #else
1279  usleep(10000L);
1280 #endif
1281 
1282  MyLog(LOGA_DEBUG, "Stopping");
1283 
1284  exit: MQTTAsync_destroy(&c);
1285  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1286  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1288  return failures;
1289 }
1290 
1291 /*********************************************************************
1292 
1293  Test3a: Server Authentication - server certificate in client trust store
1294 
1295  *********************************************************************/
1296 
1298 {
1299  AsyncTestClient* client = (AsyncTestClient*) context;
1300  MyLog(LOGA_DEBUG, "In test3aOnConnectFailure callback, context %p", context);
1301 
1302  assert("There should be no failures in this test. ", 0, "test3aOnConnectFailure callback was called\n", 0);
1303  client->testFinished = 1;
1304 }
1305 
1307 {
1308  char* testname = "test3a";
1309  int subsqos = 2;
1310  /* TODO - usused - remove ? MQTTAsync_deliveryToken* dt = NULL; */
1311  AsyncTestClient tc =
1313  MQTTAsync c;
1317  int rc = 0;
1318  int i;
1319 
1320  failures = 0;
1321 
1322  MyLog(LOGA_INFO, "Starting test 3a - Server authentication");
1323  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1325 
1327 
1328  tc.client = c;
1329  sprintf(tc.clientid, "%s", testname);
1330  sprintf(tc.topic, "C client SSL test3a");
1331  tc.maxmsgs = MAXMSGS;
1332  //tc.rcvdmsgs = 0;
1333  tc.subscribed = 0;
1334  tc.testFinished = 0;
1335 
1336  opts.keepAliveInterval = 20;
1337  opts.cleansession = 1;
1338  opts.username = "testuser";
1339  opts.password = "testpassword";
1340 
1341  opts.will = &wopts;
1342  opts.will->message = "will message";
1343  opts.will->qos = 1;
1344  opts.will->retained = 0;
1345  opts.will->topicName = "will topic";
1346  opts.will = NULL;
1349  opts.context = &tc;
1350 
1351  opts.ssl = &sslopts;
1352  if (options.server_key_file != NULL)
1353  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
1354  //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1355  //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
1356  //opts.ssl->enabledCipherSuites = "DEFAULT";
1357  //opts.ssl->enabledServerCertAuth = 1;
1358 
1361  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1362 
1363  MyLog(LOGA_DEBUG, "Connecting");
1364  rc = MQTTAsync_connect(c, &opts);
1365  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1366  if (rc != MQTTASYNC_SUCCESS)
1367  goto exit;
1368 
1369  while (!tc.subscribed && !tc.testFinished)
1370 #if defined(_WIN32)
1371  Sleep(100);
1372 #else
1373  usleep(10000L);
1374 #endif
1375 
1376  if (tc.testFinished)
1377  goto exit;
1378 
1379  for (i = 0; i < 3; i++)
1380  {
1382 
1383  pubmsg.payload
1384  = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1385  pubmsg.payloadlen = 11;
1386  pubmsg.qos = i;
1387  pubmsg.retained = 0;
1388 
1390  opts.onSuccess = asyncTestOnSend;
1391  opts.context = &tc;
1392 
1393  rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
1394  pubmsg.qos, pubmsg.retained, &opts);
1395  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1396  }
1397 
1398  while (!tc.testFinished)
1399 #if defined(_WIN32)
1400  Sleep(100);
1401 #else
1402  usleep(10000L);
1403 #endif
1404 
1405  MyLog(LOGA_DEBUG, "Stopping");
1406 
1407  MQTTAsync_destroy(&c);
1408 
1409  exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", (failures
1410  == 0) ? "passed" : "failed", testname, tests, failures);
1412  return failures;
1413 }
1414 
1415 /*********************************************************************
1416 
1417  Test3b: Server Authentication - Client does not have server cert
1418 
1419  *********************************************************************/
1420 
1422 
1424 {
1425  MyLog(LOGA_DEBUG, "In test3bOnConnectFailure callback, context %p", context);
1426 
1427  assert("This test should call test3bOnConnectFailure. ", 1, "test3bOnConnectFailure callback was called\n", 1);
1428  test3bFinished = 1;
1429 }
1430 
1432 {
1433  MyLog(LOGA_DEBUG, "In test3bOnConnectFailure callback, context %p", context);
1434 
1435  assert("This connect should not succeed. ", 0, "test3bOnConnect callback was called\n", 0);
1436  test3bFinished = 1;
1437 }
1438 
1440 {
1441  char* testname = "test3b";
1442  int subsqos = 2;
1443  MQTTAsync c;
1447  int rc = 0;
1448  int count = 0;
1449 
1450  test3bFinished = 0;
1451  failures = 0;
1452  MyLog(
1453  LOGA_INFO,
1454  "Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert");
1455  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1457 
1459  NULL);
1460  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1461  if (rc != MQTTASYNC_SUCCESS)
1462  goto exit;
1463 
1464  opts.keepAliveInterval = 20;
1465  opts.cleansession = 1;
1466  opts.username = "testuser";
1467  opts.password = "testpassword";
1468 
1469  opts.will = &wopts;
1470  opts.will->message = "will message";
1471  opts.will->qos = 1;
1472  opts.will->retained = 0;
1473  opts.will->topicName = "will topic";
1474  opts.will = NULL;
1475  opts.onSuccess = test3bOnConnect;
1477  opts.context = c;
1478 
1479  opts.ssl = &sslopts;
1480  //if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
1481  //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1482  //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
1483  //opts.ssl->enabledCipherSuites = "DEFAULT";
1484  //opts.ssl->enabledServerCertAuth = 0;
1485 
1486  MyLog(LOGA_DEBUG, "Connecting");
1487  rc = MQTTAsync_connect(c, &opts);
1488  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1489  if (rc != MQTTASYNC_SUCCESS)
1490  goto exit;
1491 
1492  while (!test3bFinished && ++count < 10000)
1493 #if defined(_WIN32)
1494  Sleep(100);
1495 #else
1496  usleep(10000L);
1497 #endif
1498 
1499  exit: MQTTAsync_destroy(&c);
1500  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1501  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1503  return failures;
1504 }
1505 
1506 /*********************************************************************
1507 
1508  Test4: Accept invalid server certificates
1509 
1510  *********************************************************************/
1511 
1513 {
1514  AsyncTestClient* client = (AsyncTestClient*) context;
1515  MyLog(LOGA_DEBUG, "In test4OnConnectFailure callback, context %p", context);
1516 
1517  assert("There should be no failures in this test. ", 0, "test4OnConnectFailure callback was called\n", 0);
1518  client->testFinished = 1;
1519 }
1520 
1522 {
1523  MyLog(LOGA_DEBUG, "In test4OnPublishFailure callback, context %p", context);
1524 
1525  assert("There should be no failures in this test. ", 0, "test4OnPublishFailure callback was called\n", 0);
1526 }
1527 
1528 int test4(struct Options options)
1529 {
1530  char* testname = "test4";
1531  int subsqos = 2;
1532  /* TODO - usused - remove ? MQTTAsync_deliveryToken* dt = NULL; */
1533  AsyncTestClient tc =
1535  MQTTAsync c;
1539  int rc = 0;
1540  int i;
1541 
1542  failures = 0;
1543 
1544  MyLog(LOGA_INFO, "Starting test 4 - accept invalid server certificates");
1545  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1547 
1549 
1550  tc.client = c;
1551  sprintf(tc.clientid, "%s", testname);
1552  sprintf(tc.topic, "C client SSL test4");
1553  tc.maxmsgs = MAXMSGS;
1554  //tc.rcvdmsgs = 0;
1555  tc.subscribed = 0;
1556  tc.testFinished = 0;
1557 
1558  opts.keepAliveInterval = 20;
1559  opts.cleansession = 1;
1560  opts.username = "testuser";
1561  opts.password = "testpassword";
1562 
1563  opts.will = &wopts;
1564  opts.will->message = "will message";
1565  opts.will->qos = 1;
1566  opts.will->retained = 0;
1567  opts.will->topicName = "will topic";
1568  opts.will = NULL;
1571  opts.context = &tc;
1572 
1573  opts.ssl = &sslopts;
1574  //if (options.server_key_file != NULL) opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
1575  //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1576  //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
1577  //opts.ssl->enabledCipherSuites = "DEFAULT";
1578  opts.ssl->enableServerCertAuth = 0;
1579 
1582  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1583 
1584  MyLog(LOGA_DEBUG, "Connecting");
1585  rc = MQTTAsync_connect(c, &opts);
1586  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1587  if (rc != MQTTASYNC_SUCCESS)
1588  goto exit;
1589 
1590  while (!tc.subscribed && !tc.testFinished)
1591 #if defined(_WIN32)
1592  Sleep(100);
1593 #else
1594  usleep(10000L);
1595 #endif
1596 
1597  if (tc.testFinished)
1598  goto exit;
1599 
1600  while (!tc.testFinished)
1601 #if defined(_WIN32)
1602  Sleep(100);
1603 #else
1604  usleep(10000L);
1605 #endif
1606 
1607  MyLog(LOGA_DEBUG, "Stopping");
1608 
1609  exit: MQTTAsync_destroy(&c);
1610  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1611  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1613  return failures;
1614 }
1615 
1616 /*********************************************************************
1617 
1618  Test5a: Anonymous ciphers - server auth disabled
1619 
1620  *********************************************************************/
1621 
1623 {
1624  AsyncTestClient* client = (AsyncTestClient*) context;
1625  MyLog(LOGA_DEBUG, "In test5aOnConnectFailure callback, context %p", context);
1626 
1627  assert("There should be no failures in this test. ", 0, "test5aOnConnectFailure callback was called\n", 0);
1628  client->testFinished = 1;
1629 }
1630 
1632 {
1633  MyLog(LOGA_DEBUG, "In test5aOnPublishFailure callback, context %p", context);
1634 
1635  assert("There should be no failures in this test. ", 0, "test5aOnPublishFailure callback was called\n", 0);
1636 }
1637 
1639 {
1640  char* testname = "test5a";
1641 
1642  AsyncTestClient tc =
1644  MQTTAsync c;
1648  int rc = 0;
1649  int i;
1650 
1651  failures = 0;
1652 
1653  MyLog(LOGA_INFO,
1654  "Starting SSL test 5a - Anonymous ciphers - server authentication disabled");
1655  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1657 
1659  NULL);
1660  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1661  if (rc != MQTTASYNC_SUCCESS)
1662  goto exit;
1663 
1664  tc.client = c;
1665  sprintf(tc.clientid, "%s", testname);
1666  sprintf(tc.topic, "C client SSL test5a");
1667  tc.maxmsgs = MAXMSGS;
1668  //tc.rcvdmsgs = 0;
1669  tc.subscribed = 0;
1670  tc.testFinished = 0;
1671 
1672  opts.keepAliveInterval = 20;
1673  opts.cleansession = 1;
1674  opts.username = "testuser";
1675  opts.password = "testpassword";
1676 
1677  opts.will = &wopts;
1678  opts.will->message = "will message";
1679  opts.will->qos = 1;
1680  opts.will->retained = 0;
1681  opts.will->topicName = "will topic";
1682  opts.will = NULL;
1685  opts.context = &tc;
1686 
1687  opts.ssl = &sslopts;
1688  //opts.ssl->trustStore = /*file of certificates trusted by client*/
1689  //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1690  //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
1691  opts.ssl->enabledCipherSuites = "aNULL";
1692  opts.ssl->enableServerCertAuth = 0;
1693 
1696  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1697 
1698  MyLog(LOGA_DEBUG, "Connecting");
1699  rc = MQTTAsync_connect(c, &opts);
1700  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1701  if (rc != MQTTASYNC_SUCCESS)
1702  goto exit;
1703 
1704  while (!tc.subscribed && !tc.testFinished)
1705 #if defined(_WIN32)
1706  Sleep(100);
1707 #else
1708  usleep(10000L);
1709 #endif
1710 
1711  if (tc.testFinished)
1712  goto exit;
1713 
1714  for (i = 0; i < 3; i++)
1715  {
1717 
1718  pubmsg.payload
1719  = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1720  pubmsg.payloadlen = 11;
1721  pubmsg.qos = i;
1722  pubmsg.retained = 0;
1723 
1725  opts.onSuccess = asyncTestOnSend;
1726  opts.context = &tc;
1727 
1728  rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
1729  pubmsg.qos, pubmsg.retained, &opts);
1730  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1731  }
1732 
1733  while (!tc.testFinished)
1734 #if defined(_WIN32)
1735  Sleep(100);
1736 #else
1737  usleep(10000L);
1738 #endif
1739 
1740  MyLog(LOGA_DEBUG, "Stopping");
1741 
1742  exit: MQTTAsync_destroy(&c);
1743  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1744  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1746  return failures;
1747 }
1748 
1749 /*********************************************************************
1750 
1751  Test5b: Anonymous ciphers - server auth enabled
1752 
1753  ********************************************************************/
1754 
1756 {
1757  AsyncTestClient* client = (AsyncTestClient*) context;
1758  MyLog(LOGA_DEBUG, "In test5bOnConnectFailure callback, context %p", context);
1759 
1760  assert("There should be no failures in this test. ", 0, "test5bOnConnectFailure callback was called\n", 0);
1761  client->testFinished = 1;
1762 }
1763 
1765 {
1766  MyLog(LOGA_DEBUG, "In test5bOnPublishFailure callback, context %p", context);
1767 
1768  assert("There should be no failures in this test. ", 0, "test5bOnPublishFailure callback was called\n", 0);
1769 }
1770 
1772 {
1773  char* testname = "test5b";
1774 
1775  AsyncTestClient tc =
1777  MQTTAsync c;
1781  int rc = 0;
1782  int i;
1783 
1784  failures = 0;
1785 
1786  MyLog(LOGA_INFO,
1787  "Starting SSL test 5b - Anonymous ciphers - server authentication enabled");
1788  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1790 
1792  NULL);
1793  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1794  if (rc != MQTTASYNC_SUCCESS)
1795  goto exit;
1796 
1797  tc.client = c;
1798  sprintf(tc.clientid, "%s", testname);
1799  sprintf(tc.topic, "C client SSL test5b");
1800  tc.maxmsgs = MAXMSGS;
1801  //tc.rcvdmsgs = 0;
1802  tc.subscribed = 0;
1803  tc.testFinished = 0;
1804 
1805  opts.keepAliveInterval = 20;
1806  opts.cleansession = 1;
1807  opts.username = "testuser";
1808  opts.password = "testpassword";
1809 
1810  opts.will = &wopts;
1811  opts.will->message = "will message";
1812  opts.will->qos = 1;
1813  opts.will->retained = 0;
1814  opts.will->topicName = "will topic";
1815  opts.will = NULL;
1818  opts.context = &tc;
1819 
1820  opts.ssl = &sslopts;
1821  //opts.ssl->trustStore = /*file of certificates trusted by client*/
1822  //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1823  //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
1824  opts.ssl->enabledCipherSuites = "aNULL";
1825  opts.ssl->enableServerCertAuth = 1;
1826 
1829  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1830 
1831  MyLog(LOGA_DEBUG, "Connecting");
1832  rc = MQTTAsync_connect(c, &opts);
1833  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1834  if (rc != MQTTASYNC_SUCCESS)
1835  goto exit;
1836 
1837  while (!tc.subscribed && !tc.testFinished)
1838 #if defined(_WIN32)
1839  Sleep(100);
1840 #else
1841  usleep(10000L);
1842 #endif
1843 
1844  if (tc.testFinished)
1845  goto exit;
1846 
1847  for (i = 0; i < 3; i++)
1848  {
1850 
1851  pubmsg.payload
1852  = "a much longer message that we can shorten to the extent that we need to payload up to 11";
1853  pubmsg.payloadlen = 11;
1854  pubmsg.qos = i;
1855  pubmsg.retained = 0;
1856 
1858  opts.onSuccess = asyncTestOnSend;
1859  opts.context = &tc;
1860 
1861  rc = MQTTAsync_send(c, tc.topic, pubmsg.payloadlen, pubmsg.payload,
1862  pubmsg.qos, pubmsg.retained, &opts);
1863  assert("Good rc from publish", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
1864  }
1865 
1866  while (!tc.testFinished)
1867 #if defined(_WIN32)
1868  Sleep(100);
1869 #else
1870  usleep(10000L);
1871 #endif
1872 
1873  MyLog(LOGA_DEBUG, "Stopping");
1874 
1875  exit: MQTTAsync_destroy(&c);
1876  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1877  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1879  return failures;
1880 }
1881 
1882 /*********************************************************************
1883 
1884  Test5c: Anonymous ciphers - client not using anonymous ciphers
1885 
1886  *********************************************************************/
1887 
1889 
1891 {
1892  MyLog(LOGA_DEBUG, "In test5cOnConnectFailure callback, context %p", context);
1893 
1894  assert("This test should call test5cOnConnectFailure. ", 1, "test5cOnConnectFailure callback was called\n", 1);
1895  test5cFinished = 1;
1896 }
1897 
1899 {
1900  MyLog(LOGA_DEBUG, "In test5cOnConnectFailure callback, context %p", context);
1901 
1902  assert("This connect should not succeed. ", 0, "test5cOnConnect callback was called\n", 0);
1903  test5cFinished = 1;
1904 }
1905 
1907 {
1908  char* testname = "test5c";
1909  int subsqos = 2;
1910  MQTTAsync c;
1914  int rc = 0;
1915  int count = 0;
1916 
1917  test5cFinished = 0;
1918  failures = 0;
1919  MyLog(LOGA_INFO,
1920  "Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher");
1921  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
1923 
1925  NULL);
1926  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1927  if (rc != MQTTASYNC_SUCCESS)
1928  goto exit;
1929 
1930  opts.keepAliveInterval = 20;
1931  opts.cleansession = 1;
1932  opts.username = "testuser";
1933  opts.password = "testpassword";
1934 
1935  opts.will = &wopts;
1936  opts.will->message = "will message";
1937  opts.will->qos = 1;
1938  opts.will->retained = 0;
1939  opts.will->topicName = "will topic";
1940  opts.will = NULL;
1941  opts.onSuccess = test5cOnConnect;
1943  opts.context = c;
1944 
1945  opts.ssl = &sslopts;
1946  //opts.ssl->trustStore = /*file of certificates trusted by client*/
1947  //opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
1948  //if (options.client_key_pass != NULL) opts.ssl->privateKeyPassword = options.client_key_pass;
1949  //opts.ssl->enabledCipherSuites = "DEFAULT";
1950  opts.ssl->enableServerCertAuth = 0;
1951 
1952  MyLog(LOGA_DEBUG, "Connecting");
1953  rc = MQTTAsync_connect(c, &opts);
1954  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
1955  if (rc != MQTTASYNC_SUCCESS)
1956  goto exit;
1957 
1958  while (!test5cFinished && ++count < 10000)
1959 #if defined(_WIN32)
1960  Sleep(100);
1961 #else
1962  usleep(10000L);
1963 #endif
1964 
1965 exit:
1966  MQTTAsync_destroy(&c);
1967  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
1968  (failures == 0) ? "passed" : "failed", testname, tests, failures);
1970  return failures;
1971 }
1972 
1973 /*********************************************************************
1974 
1975  Test6: More than one client object - simultaneous working.
1976 
1977  *********************************************************************/
1978 
1980 {
1981  AsyncTestClient* client = (AsyncTestClient*) context;
1982  MyLog(LOGA_DEBUG, "In test6OnConnectFailure callback, context %p", context);
1983 
1984  assert("There should be no failures in this test. ", 0, "test6OnConnectFailure callback was called\n", 0);
1985  client->testFinished = 1;
1986 }
1987 
1989 {
1990  MyLog(LOGA_DEBUG, "In test6OnPublishFailure callback, context %p", context);
1991 
1992  assert("There should be no failures in this test. ", 0, "test6OnPublishFailure callback was called\n", 0);
1993 }
1994 
1995 int test6(struct Options options)
1996 {
1997  char* testname = "test6";
1998 #define num_clients 10
1999  int subsqos = 2;
2003  int rc = 0;
2004  int i;
2006  int test6finished = 0;
2007 
2008  MyLog(LOGA_INFO, "Starting test 6 - multiple connections");
2009  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
2011 
2012  for (i = 0; i < num_clients; ++i)
2013  {
2014  tc[i].maxmsgs = MAXMSGS;
2015  tc[i].rcvdmsgs[0] = 0;
2016  tc[i].rcvdmsgs[1] = 0;
2017  tc[i].rcvdmsgs[2] = 0;
2018  tc[i].sentmsgs[0] = 0;
2019  tc[i].sentmsgs[1] = 0;
2020  tc[i].sentmsgs[2] = 0;
2021  tc[i].testFinished = 0;
2022  sprintf(tc[i].clientid, "sslasync_test6_num_%d", i);
2023  sprintf(tc[i].topic, "sslasync test6 topic num %d", i);
2024 
2025  rc = MQTTAsync_create(&(tc[i].client), options.server_auth_connection, tc[i].clientid,
2027  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2028 
2029  rc = MQTTAsync_setCallbacks(tc[i].client, &tc[i], NULL,
2030  asyncTestMessageArrived, NULL);
2031  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2032 
2033  opts.keepAliveInterval = 20;
2034  opts.cleansession = 1;
2035  opts.username = "testuser";
2036  opts.password = "testpassword";
2037 
2038  opts.will = &wopts;
2039  opts.will->message = "will message";
2040  opts.will->qos = 1;
2041  opts.will->retained = 0;
2042  opts.will->topicName = "will topic";
2045  opts.context = &tc[i];
2046 
2047  opts.ssl = &sslopts;
2048  if (options.server_key_file != NULL)
2049  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
2050  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
2051  if (options.client_key_pass != NULL)
2052  opts.ssl->privateKeyPassword = options.client_key_pass;
2053  //opts.ssl->enabledCipherSuites = "DEFAULT";
2054  //opts.ssl->enabledServerCertAuth = 1;
2055 
2056  MyLog(LOGA_DEBUG, "Connecting");
2057  rc = MQTTAsync_connect(tc[i].client, &opts);
2058  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2059  }
2060 
2061  while (test6finished < num_clients)
2062  {
2063  MyLog(LOGA_DEBUG, "num_clients %d test_finished %d\n", num_clients,
2064  test6finished);
2065 #if defined(_WIN32)
2066  Sleep(100);
2067 
2068 #else
2069  usleep(10000L);
2070 #endif
2071  for (i = 0; i < num_clients; ++i)
2072  {
2073  if (tc[i].testFinished)
2074  {
2075  test6finished++;
2076  tc[i].testFinished = 0;
2077  }
2078  }
2079  }
2080 
2081  MyLog(LOGA_DEBUG, "test6: destroying clients");
2082 
2083  for (i = 0; i < num_clients; ++i)
2084  MQTTAsync_destroy(&tc[i].client);
2085 
2086 //exit:
2087  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2088  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2090  return failures;
2091 }
2092 
2093 /*********************************************************************
2094 
2095  Test7: Send and receive big messages
2096 
2097  *********************************************************************/
2098 
2099 void* test7_payload = NULL;
2101 
2103 {
2104  AsyncTestClient* client = (AsyncTestClient*) context;
2105  MyLog(LOGA_DEBUG, "In test7OnConnectFailure callback, %s", client->clientid);
2106 
2107  assert("There should be no failures in this test. ", 0, "test7OnConnectFailure callback was called\n", 0);
2108  client->testFinished = 1;
2109 }
2110 
2113 
2115 {
2116  AsyncTestClient* tc = (AsyncTestClient*) context;
2117 
2118  MyLog(LOGA_DEBUG, "In test7OnPublishSuccess callback, %s, qos %d", tc->clientid,
2119  response->alt.pub.message.qos);
2120 
2122 }
2123 
2125 {
2126  AsyncTestClient* client = (AsyncTestClient*) context;
2127  MyLog(LOGA_DEBUG, "In test7OnPublishFailure callback, %s %d", client->clientid);
2128 
2129  assert("There should be no failures in this test. ", 0, "test7OnPublishFailure callback was called\n", 0);
2130  client->testFinished = 1;
2131 }
2132 
2134 {
2135  AsyncTestClient* tc = (AsyncTestClient*) context;
2136  int rc;
2137 
2138  MyLog(LOGA_DEBUG, "In test7OnUnsubscribe callback, %s %d %d", tc->clientid,
2140 
2142 }
2143 
2144 int test7MessageArrived(void* context, char* topicName, int topicLen,
2145  MQTTAsync_message* message)
2146 {
2147  AsyncTestClient* tc = (AsyncTestClient*) context;
2148  static int message_count = 0;
2149  int rc, i;
2150 
2151  MyLog(LOGA_DEBUG, "In messageArrived callback %p", tc);
2152 
2153  assert("Message size correct", message->payloadlen == test7_payloadlen,
2154  "message size was %d", message->payloadlen);
2155 
2156  for (i = 0; i < options.size; ++i)
2157  {
2158  if (((char*) test7_payload)[i] != ((char*) message->payload)[i])
2159  {
2160  assert("Message contents correct", ((char*)test7_payload)[i] != ((char*)message->payload)[i],
2161  "message content was %c", ((char*)message->payload)[i]);
2162  break;
2163  }
2164  }
2165 
2166  if (++message_count == 1)
2167  {
2170 
2171  pubmsg.payload = test7_payload;
2172  pubmsg.payloadlen = test7_payloadlen;
2173  pubmsg.qos = 1;
2174  pubmsg.retained = 0;
2177  opts.context = tc;
2178 
2179  rc = MQTTAsync_sendMessage(tc->client, tc->topic, &pubmsg, &opts);
2180  }
2181  else if (message_count < options.message_count)
2182  {
2185 
2186  pubmsg.payload = test7_payload;
2187  pubmsg.payloadlen = test7_payloadlen;
2188  pubmsg.qos = 0;
2189  pubmsg.retained = 0;
2192  opts.context = tc;
2193  rc = MQTTAsync_sendMessage(tc->client, tc->topic, &pubmsg, &opts);
2194  }
2195  else
2196  {
2198 
2200  opts.context = tc;
2201  rc = MQTTAsync_unsubscribe(tc->client, tc->topic, &opts);
2202  assert("Unsubscribe successful", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2203  }
2204 
2205  MQTTAsync_freeMessage(&message);
2206  MQTTAsync_free(topicName);
2207 
2208  return 1;
2209 }
2210 
2211 
2213 {
2214  AsyncTestClient* tc = (AsyncTestClient*) context;
2217  int rc, i;
2218 
2219  MyLog(LOGA_DEBUG, "In subscribe onSuccess callback %p", tc);
2220 
2221  pubmsg.payload = test7_payload = malloc(options.size);
2223 
2224  srand(33);
2225  for (i = 0; i < options.size; ++i)
2226  ((char*) pubmsg.payload)[i] = rand() % 256;
2227 
2228  pubmsg.qos = 2;
2229  pubmsg.retained = 0;
2230 
2231  pubmsg.payload = test7_payload;
2232  pubmsg.payloadlen = test7_payloadlen;
2235  opts.context = tc;
2236 
2237  rc = MQTTAsync_send(tc->client, tc->topic, pubmsg.payloadlen, pubmsg.payload,
2238  pubmsg.qos, pubmsg.retained, &opts);
2239 }
2240 
2242 {
2243  AsyncTestClient* tc = (AsyncTestClient*) context;
2245  int rc;
2246 
2247  MyLog(LOGA_DEBUG, "In connect onSuccess callback, context %p", context);
2248  opts.onSuccess = test7OnSubscribe;
2249  opts.context = tc;
2250 
2251  rc = MQTTAsync_subscribe(tc->client, tc->topic, 2, &opts);
2252  assert("Good rc from subscribe", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2253  if (rc != MQTTASYNC_SUCCESS)
2254  tc->testFinished = 1;
2255 }
2256 
2257 int test7(struct Options options)
2258 {
2259  char* testname = "test7";
2260  int subsqos = 2;
2262  MQTTAsync c;
2267  int rc = 0;
2268  char* test_topic = "C client test7";
2269  int test_finished;
2270 
2271  test_finished = failures = 0;
2272 
2273  MyLog(LOGA_INFO, "Starting test 7 - big messages");
2274  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
2276 
2277  rc = MQTTAsync_create(&c, options.server_auth_connection, "async_test_7", MQTTCLIENT_PERSISTENCE_NONE,
2278  NULL);
2279  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2280  if (rc != MQTTASYNC_SUCCESS)
2281  {
2282  MQTTAsync_destroy(&c);
2283  goto exit;
2284  }
2285 
2286  rc = MQTTAsync_setCallbacks(c, &tc, NULL, test7MessageArrived, NULL);
2287  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2288 
2289  tc.client = c;
2290  sprintf(tc.clientid, "%s", testname);
2291  sprintf(tc.topic, "C client SSL test7");
2292  tc.maxmsgs = MAXMSGS;
2293  //tc.rcvdmsgs = 0;
2294  tc.subscribed = 0;
2295  tc.testFinished = 0;
2296 
2297  opts.keepAliveInterval = 20;
2298  opts.cleansession = 1;
2299  //opts.username = "testuser";
2300  //opts.password = "testpassword";
2301 
2302  opts.will = &wopts;
2303  opts.will->message = "will message";
2304  opts.will->qos = 1;
2305  opts.will->retained = 0;
2306  opts.will->topicName = "will topic";
2307  opts.will = NULL;
2308  opts.onSuccess = test7OnConnect;
2310  opts.context = &tc;
2311 
2312  opts.ssl = &sslopts;
2313  if (options.server_key_file != NULL)
2314  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
2315  if (options.client_key_file != NULL)
2316  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
2317  if (options.client_key_pass != NULL)
2318  opts.ssl->privateKeyPassword = options.client_key_pass;
2319  //opts.ssl->enabledCipherSuites = "DEFAULT";
2320  //opts.ssl->enabledServerCertAuth = 1;
2321 
2322  MyLog(LOGA_DEBUG, "Connecting");
2323  rc = MQTTAsync_connect(c, &opts);
2324  rc = 0;
2325  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2326  if (rc != MQTTASYNC_SUCCESS)
2327  goto exit;
2328 
2330 #if defined(_WIN32)
2331  Sleep(100);
2332 #else
2333  usleep(1000L);
2334 #endif
2335 
2337  dopts.context = &tc;
2338  rc = MQTTAsync_disconnect(c, &dopts);
2339 
2340  while (!tc.testFinished)
2341 #if defined(_WIN32)
2342  Sleep(100);
2343 #else
2344  usleep(1000L);
2345 #endif
2346 
2347  MQTTAsync_destroy(&c);
2348 
2349  if (test7_payload)
2350  {
2352  test7_payload = NULL;
2353  }
2354 
2355  exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2356  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2358  return failures;
2359 }
2360 
2361 /*********************************************************************
2362 
2363 Test8: TLS-PSK - client and server has a common pre-shared key
2364 
2365 *********************************************************************/
2366 
2367 static unsigned int onPSKAuth(const char* hint,
2368  char* identity,
2369  unsigned int max_identity_len,
2370  unsigned char* psk,
2371  unsigned int max_psk_len,
2372  void* context)
2373 {
2374  unsigned char test_psk[] = {0x50, 0x53, 0x4B, 0x00}; /* {'P', 'S', 'K', '\0' } */
2375  MyLog(LOGA_DEBUG, "PSK auth callback");
2376 
2377  assert("Good application context in onPSKAuth", context == (void *) 42, "context was %d\n", context);
2378 
2379  strncpy(identity, "id", max_identity_len);
2380  memcpy(psk, test_psk, sizeof(test_psk));
2381  return sizeof(test_psk);
2382 }
2383 
2384 
2385 int test8(struct Options options)
2386 {
2387  char* testname = "test8";
2388 
2389  AsyncTestClient tc =
2391  MQTTAsync c;
2395  int rc = 0;
2396 
2397  failures = 0;
2398  MyLog(LOGA_INFO, "Starting test 8 - TLS-PSK - client and server has a common pre-shared key");
2399  fprintf(xml, "<testcase classname=\"test8\" name=\"%s\"", testname);
2401 
2402  MQTTAsync_create(&c, options.psk_connection, "test8", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
2403  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2404  if (rc != MQTTASYNC_SUCCESS)
2405  goto exit;
2406 
2407  tc.client = c;
2408  sprintf(tc.clientid, "%s", testname);
2409  sprintf(tc.topic, "C client SSL test8");
2410  tc.maxmsgs = MAXMSGS;
2411  tc.subscribed = 0;
2412  tc.testFinished = 0;
2413 
2414  opts.keepAliveInterval = 20;
2415  opts.cleansession = 1;
2416  opts.username = "testuser";
2417  opts.password = "testpassword";
2418 
2421  opts.context = &tc;
2422 
2423  opts.ssl = &sslopts;
2424  opts.ssl->ssl_psk_cb = onPSKAuth;
2425  opts.ssl->ssl_psk_context = (void *) 42;
2426  opts.ssl->enabledCipherSuites = "PSK-AES128-CBC-SHA";
2427 
2430  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2431 
2432  MyLog(LOGA_DEBUG, "Connecting");
2433  rc = MQTTAsync_connect(c, &opts);
2434  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2435  if (rc != MQTTASYNC_SUCCESS)
2436  goto exit;
2437 
2438  while (!tc.subscribed && !tc.testFinished)
2439 #if defined(_WIN32)
2440  Sleep(100);
2441 #else
2442  usleep(10000L);
2443 #endif
2444 
2445  if (tc.testFinished)
2446  goto exit;
2447 
2448  while (!tc.testFinished)
2449 #if defined(_WIN32)
2450  Sleep(100);
2451 #else
2452  usleep(10000L);
2453 #endif
2454 
2455  MyLog(LOGA_DEBUG, "Stopping");
2456 
2457 exit:
2458  MQTTAsync_destroy(&c);
2459  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2460  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2462  return failures;
2463 }
2464 
2465 
2466 /*********************************************************************
2467 
2468  Test9: Mutual SSL Authentication - Testing CApath
2469 
2470  *********************************************************************/
2471 
2473 {
2474  AsyncTestClient* client = (AsyncTestClient*) context;
2475  MyLog(LOGA_DEBUG, "In test9OnConnectFailure callback, %s",
2476  client->clientid);
2477 
2478  assert("There should be no failures in this test. ", 0, "test9OnConnectFailure callback was called\n", 0);
2479  client->testFinished = 1;
2480 }
2481 
2482 int test9(struct Options options)
2483 {
2484  char* testname = "test9";
2485 
2486  AsyncTestClient tc =
2488  MQTTAsync c;
2492  int rc = 0;
2493 
2494  failures = 0;
2495  MyLog(LOGA_INFO, "Starting test 9 - Mutual SSL authentication with CApath");
2496  fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
2498 
2500  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2501  if (rc != MQTTASYNC_SUCCESS)
2502  goto exit;
2503 
2504  tc.client = c;
2505  sprintf(tc.clientid, "%s", testname);
2506  sprintf(tc.topic, "C client SSL test9");
2507  tc.maxmsgs = MAXMSGS;
2508  //tc.rcvdmsgs = 0;
2509  tc.subscribed = 0;
2510  tc.testFinished = 0;
2511 
2512  opts.keepAliveInterval = 20;
2513  opts.cleansession = 1;
2514  opts.username = "testuser";
2515  opts.password = "testpassword";
2516 
2517  opts.will = &wopts;
2518  opts.will->message = "will message";
2519  opts.will->qos = 1;
2520  opts.will->retained = 0;
2521  opts.will->topicName = "will topic";
2522  opts.will = NULL;
2525  opts.context = &tc;
2526 
2527  opts.ssl = &sslopts;
2528  if (options.server_key_file != NULL)
2529  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
2530  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
2531  if (options.client_key_pass != NULL)
2532  opts.ssl->privateKeyPassword = options.client_key_pass;
2533  opts.ssl->CApath = options.capath;
2534  opts.ssl->enableServerCertAuth = 1;
2535  opts.ssl->verify = 1;
2536  MyLog(LOGA_DEBUG, "enableServerCertAuth %d\n", opts.ssl->enableServerCertAuth);
2537  MyLog(LOGA_DEBUG, "verify %d\n", opts.ssl->verify);
2538 
2541  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2542 
2543  MyLog(LOGA_DEBUG, "Connecting");
2544  rc = MQTTAsync_connect(c, &opts);
2545  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2546  if (rc != MQTTASYNC_SUCCESS)
2547  goto exit;
2548 
2549  while (!tc.subscribed && !tc.testFinished)
2550 #if defined(_WIN32)
2551  Sleep(100);
2552 #else
2553  usleep(10000L);
2554 #endif
2555 
2556  if (tc.testFinished)
2557  goto exit;
2558 
2559  while (!tc.testFinished)
2560 #if defined(_WIN32)
2561  Sleep(100);
2562 #else
2563  usleep(10000L);
2564 #endif
2565 
2566  MyLog(LOGA_DEBUG, "Stopping");
2567 
2568  exit: MQTTAsync_destroy(&c);
2569  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2570  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2572  return failures;
2573 }
2574 
2575 /*********************************************************************
2576 
2577  Test10: Mutual SSL Authentication - Testing CApath
2578 
2579  *********************************************************************/
2580 
2582 
2584 {
2585  AsyncTestClient* client = (AsyncTestClient*) context;
2586  MyLog(LOGA_DEBUG, "In test10OnConnectFailure callback, %s",
2587  client->clientid);
2588 
2589  assert("This test should call test10OnConnectFailure. ", 1, "test10OnConnectFailure callback was called\n", 1);
2590  test10Finished = 1;
2591 }
2592 
2594 {
2595  MyLog(LOGA_DEBUG, "In test10OnConnect callback, context %p", context);
2596 
2597  assert("This connect should not succeed. ", 0, "test10OnConnect callback was called\n", 0);
2598  test10Finished = 1;
2599 }
2600 
2602 {
2603  char* testname = "test10";
2604 
2605  AsyncTestClient tc =
2607  MQTTAsync c;
2611  int rc = 0;
2612 
2613  failures = 0;
2614  test10Finished = 0;
2615  MyLog(LOGA_INFO, "Starting test 10 - dummy CApath");
2616  fprintf(xml, "<testcase classname=\"test10\" name=\"%s\"", testname);
2618 
2620  assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
2621  if (rc != MQTTASYNC_SUCCESS)
2622  goto exit;
2623 
2624 
2625  tc.client = c;
2626  sprintf(tc.clientid, "%s", testname);
2627  sprintf(tc.topic, "C client SSL test10");
2628  tc.maxmsgs = MAXMSGS;
2629  //tc.rcvdmsgs = 0;
2630  tc.subscribed = 0;
2631  tc.testFinished = 0;
2632 
2633  opts.keepAliveInterval = 20;
2634  opts.cleansession = 1;
2635  opts.username = "testuser";
2636  opts.password = "testpassword";
2637 
2638  opts.will = &wopts;
2639  opts.will->message = "will message";
2640  opts.will->qos = 1;
2641  opts.will->retained = 0;
2642  opts.will->topicName = "will topic";
2643  opts.will = NULL;
2644  opts.onSuccess = test10OnConnect;
2646  opts.context = &tc;
2647 
2648  opts.ssl = &sslopts;
2649  if (options.server_key_file != NULL)
2650  opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
2651  opts.ssl->keyStore = options.client_key_file; /*file of certificate for client to present to server*/
2652  if (options.client_key_pass != NULL)
2653  opts.ssl->privateKeyPassword = options.client_key_pass;
2654  opts.ssl->CApath = "DUMMY";
2655  opts.ssl->enableServerCertAuth = 1;
2656  opts.ssl->verify = 1;
2657  MyLog(LOGA_DEBUG, "enableServerCertAuth %d\n", opts.ssl->enableServerCertAuth);
2658  MyLog(LOGA_DEBUG, "verify %d\n", opts.ssl->verify);
2659 
2662  assert("Good rc from setCallbacks", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2663 
2664  MyLog(LOGA_DEBUG, "Connecting");
2665  rc = MQTTAsync_connect(c, &opts);
2666  assert("Good rc from connect", rc == MQTTASYNC_SUCCESS, "rc was %d", rc);
2667  if (rc != MQTTASYNC_SUCCESS)
2668  goto exit;
2669 
2670  while (!test10Finished)
2671 #if defined(_WIN32)
2672  Sleep(100);
2673 #else
2674  usleep(10000L);
2675 #endif
2676  MyLog(LOGA_DEBUG, "Stopping");
2677 
2678  exit: MQTTAsync_destroy(&c);
2679  MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
2680  (failures == 0) ? "passed" : "failed", testname, tests, failures);
2682  return failures;
2683 }
2684 
2685 
2686 void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char* message)
2687 {
2688  printf("%s\n", message);
2689 }
2690 
2691 
2692 int main(int argc, char** argv)
2693 {
2694  int* numtests = &tests;
2695  int rc = 0;
2696  int (*tests[])() =
2697  { NULL, test1, test2a, test2b, test2c, test2d, test3a, test3b, test4, /* test5a,
2698  test5b, test5c, */ test6, test7, test8, test9, test10, test2e };
2699 
2700  xml = fopen("TEST-test5.xml", "w");
2701  fprintf(xml, "<testsuite name=\"test5\" tests=\"%d\">\n", (int)ARRAY_SIZE(tests) - 1);
2702 
2704  getopts(argc, argv);
2705 
2706  if (options.test_no == 0)
2707  { /* run all the tests */
2709  {
2710  failures = 0;
2712  rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
2713  }
2714  }
2715  else
2716  {
2718  rc = tests[options.test_no](options); /* run just the selected test */
2719  }
2720 
2721  MyLog(LOGA_INFO, "Total tests run: %d", *numtests);
2722  if (rc == 0)
2723  MyLog(LOGA_INFO, "verdict pass");
2724  else
2725  MyLog(LOGA_INFO, "verdict fail");
2726 
2727  fprintf(xml, "</testsuite>\n");
2728  fclose(xml);
2729 
2730  return rc;
2731 }
2732 
2733 /* Local Variables: */
2734 /* indent-tabs-mode: t */
2735 /* c-basic-offset: 8 */
2736 /* End: */
void asyncTestOnSubscribeFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:514
int testFinished
Definition: test5.c:103
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:1255
char nocert_mutual_auth_connection[100]
Definition: test3.c:76
void usage(void)
Definition: test5.c:42
const char * keyStore
Definition: MQTTAsync.h:1053
void asyncTestOnUnsubscribe(void *context, MQTTAsync_successData *response)
Definition: test5.c:523
enum MQTTPropertyCodes value
int subscribed
Definition: test5.c:104
char output[3000]
Definition: test5.c:334
#define MQTTASYNC_NULL_PARAMETER
Definition: MQTTAsync.h:140
void asyncTestOnDisconnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:492
int size
Definition: test11.c:53
const char * trustStore
Definition: MQTTAsync.h:1048
#define AsyncTestClient_initializer
Definition: test5.c:107
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
string topic
Definition: test2.py:8
char * client_private_key_file
Definition: test3.c:85
#define MAXMSGS
Definition: test5.c:328
int test7_payloadlen
Definition: test5.c:2100
union MQTTAsync_successData::@46 alt
void test3aOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1297
void write_test_result(void)
Definition: test5.c:338
int test2dFinished
Definition: test5.c:1062
#define assert(a, b, c, d)
Definition: test5.c:325
START_TIME_TYPE global_start_time
Definition: test5.c:333
const char * message
Definition: MQTTAsync.h:996
char * connection
const char * topicName
Definition: MQTTAsync.h:994
void test2eOnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1186
void test1OnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:658
int test5cFinished
Definition: test5.c:1888
#define MQTTAsync_responseOptions_initializer
Definition: MQTTAsync.h:746
void test5cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:1898
int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
Definition: MQTTAsync.c:3923
int tests
Definition: test5.c:330
void test7OnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:2241
void test2cOnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:973
#define num_clients
int test2a(struct Options options)
Definition: test5.c:769
int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
Definition: MQTTAsync.c:3062
int test1(struct Options options)
Definition: test5.c:668
int test9(struct Options options)
Definition: test5.c:2482
void handleTrace(enum MQTTASYNC_TRACE_LEVELS level, char *message)
Definition: test5.c:2686
struct pubsub_opts opts
Definition: paho_c_pub.c:42
int test2d(struct Options options)
Definition: test5.c:1080
void test4OnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1521
void test2cOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:965
void * MQTTAsync
Definition: MQTTAsync.h:239
char psk_connection[100]
Definition: test3.c:79
size_t strftime(char *str, size_t count, const char *format, const std::tm *time)
Definition: chrono.h:375
void MQTTAsync_free(void *memory)
Definition: MQTTAsync.c:2626
volatile int multiThread_arrivedcount
Definition: test5.c:381
#define malloc(x)
Definition: Heap.h:41
void MQTTAsync_freeMessage(MQTTAsync_message **message)
Definition: MQTTAsync.c:2615
int MQTTAsync_unsubscribe(MQTTAsync handle, const char *topic, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4209
void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
Definition: MQTTAsync.c:4903
int test6(struct Options options)
Definition: test5.c:1995
int test2bFinished
Definition: test5.c:868
int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
Definition: MQTTAsync.c:3480
void test2dOnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:1072
MQTTASYNC_TRACE_LEVELS
Definition: MQTTAsync.h:1650
static char msg_buf[512]
Definition: Log.c:122
char * client_key_pass
Definition: test3.c:83
#define free(x)
Definition: Heap.h:55
int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4121
void test2bOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:870
START_TIME_TYPE start_clock(void)
Definition: test5.c:291
#define MQTTAsync_willOptions_initializer
Definition: MQTTAsync.h:1014
constexpr size_t count()
Definition: core.h:960
void test1OnFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:650
char * capath
Definition: test5.c:67
FILE * xml
Definition: test5.c:332
int MQTTAsync_create(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
Definition: MQTTAsync.c:737
int sentmsgs[3]
Definition: test5.c:102
int test2c(struct Options options)
Definition: test5.c:981
void test7OnSubscribe(void *context, MQTTAsync_successData *response)
Definition: test5.c:2212
struct Options options
int multiThread_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *m)
Definition: test5.c:390
void test6OnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1988
void test6OnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1979
description
Definition: setup.py:19
#define MQTTAsync_disconnectOptions_initializer
Definition: MQTTAsync.h:1422
#define START_TIME_TYPE
Definition: test5.c:289
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:702
int message_count
Definition: test5.c:72
char mutual_auth_connection[100]
Definition: test3.c:75
void multiThread_deliveryComplete(void *context, MQTTAsync_token dt)
Definition: test5.c:385
void test2bOnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:878
#define ARRAY_SIZE(a)
Definition: test5.c:40
void asyncTestOnSend(void *context, MQTTAsync_successData *response)
Definition: test5.c:503
int test10(struct Options options)
Definition: test5.c:2601
unsigned int(* ssl_psk_cb)(const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len, void *u)
Definition: MQTTAsync.h:1113
void test3bOnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:1431
int qos
Definition: test6.c:56
int start_port
Definition: test5.c:73
void asyncTestOnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:624
int test2cFinished
Definition: test5.c:963
void test2dOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1064
void test9OnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:2472
int test3bFinished
Definition: test5.c:1421
void test2eOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1176
int main(int argc, char **argv)
Definition: test5.c:2692
MQTTAsync_message multiThread_pubmsg
Definition: test5.c:383
#define TEST2D_COUNT
#define LOGA_INFO
Definition: test5.c:228
int test_finished
Definition: test11.c:308
MQTTAsync_SSLOptions * ssl
Definition: MQTTAsync.h:1243
int test3b(struct Options options)
Definition: test5.c:1439
int test4(struct Options options)
Definition: test5.c:1528
#define MQTTAsync_connectOptions_initializer
Definition: MQTTAsync.h:1335
int MQTTAsync_token
Definition: MQTTAsync.h:249
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:696
void test7OnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:2124
int test7(struct Options options)
Definition: test5.c:2257
int asyncTestMessageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *m)
Definition: test5.c:566
MQTTAsync_willOptions * will
Definition: MQTTAsync.h:1214
const char * privateKeyPassword
Definition: MQTTAsync.h:1061
void asyncTestOnDeliveryComplete(void *context, MQTTAsync_token token)
Definition: test5.c:619
void getopts(int argc, char **argv)
Definition: test5.c:109
const char * enabledCipherSuites
Definition: MQTTAsync.h:1071
#define MQTTCLIENT_PERSISTENCE_DEFAULT
MQTTAsync client
Definition: test6.c:276
int MQTTAsync_send(MQTTAsync handle, const char *destinationName, int payloadlen, const void *payload, int qos, int retained, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4230
void test2aOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:750
void asyncTestOnSubscribe(void *context, MQTTAsync_successData *response)
Definition: test5.c:536
char server_auth_connection[100]
Definition: test3.c:77
int test7MessageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: test5.c:2144
void MQTTAsync_destroy(MQTTAsync *handle)
Definition: MQTTAsync.c:2554
void test5bOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1755
void test4OnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1512
int test5b(struct Options options)
Definition: test5.c:1771
char clientid[24]
Definition: test5.c:98
#define MQTTASYNC_SUCCESS
Definition: MQTTAsync.h:113
void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
Definition: MQTTAsync.c:4897
int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *message, MQTTAsync_responseOptions *response)
Definition: MQTTAsync.c:4328
long elapsed(START_TIME_TYPE start_time)
Definition: test5.c:315
char * test_topic
Definition: test11.c:307
int test1OnFailureCalled
Definition: test5.c:648
MQTTClient c
Definition: test10.c:1656
int test7OnPublishSuccessCount
Definition: test5.c:2111
dictionary context
Definition: test2.py:57
char * clientid
Definition: test6.c:54
int test3a(struct Options options)
Definition: test5.c:1306
null localtime_s(...)
Definition: chrono.h:286
void test7OnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:2102
struct MQTTAsync_successData::@46::@47 pub
void test2aOnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:760
#define MQTTCLIENT_PERSISTENCE_NONE
void test10OnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:2583
static unsigned int onPSKAuth(const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len, void *context)
Definition: test5.c:2367
void test10OnConnect(void *context, MQTTAsync_successData *response)
Definition: test5.c:2593
void test5bOnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1764
#define MQTTASYNC_BAD_PROTOCOL
Definition: MQTTAsync.h:177
void test5aOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1622
int failures
Definition: test5.c:331
#define MQTTAsync_SSLOptions_initializer
Definition: MQTTAsync.h:1144
MQTTAsync client
Definition: test5.c:97
void MyLog(int LOGA_level, char *format,...)
Definition: test5.c:232
#define LOGA_DEBUG
Definition: test5.c:227
void test5aOnPublishFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1631
char * cur_output
Definition: test5.c:335
char *const * serverURIs
Definition: MQTTAsync.h:1277
int test10Finished
Definition: test5.c:2581
int websockets
Definition: test3.c:88
#define MQTTAsync_message_initializer
Definition: MQTTAsync.h:319
void myassert(char *filename, int lineno, char *description, int value, char *format,...)
Definition: test5.c:351
char topic[100]
Definition: test5.c:99
enum MQTTReasonCodes rc
Definition: test10.c:1112
const char * CApath
Definition: MQTTAsync.h:1094
int test1Finished
Definition: test5.c:646
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:1249
void test7OnPublishSuccess(void *context, MQTTAsync_successData *response)
Definition: test5.c:2114
void test7OnUnsubscribe(void *context, MQTTAsync_successData *response)
Definition: test5.c:2133
int test2b(struct Options options)
Definition: test5.c:886
void test5cOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1890
void sendAndReceive(MQTTAsync *c, int qos, char *test_topic)
Definition: test5.c:409
char anon_connection[100]
Definition: test3.c:78
int multiThread_deliveryCompleted
Definition: test5.c:382
int test_no
Definition: test1.c:54
int test5a(struct Options options)
Definition: test5.c:1638
int rcvdmsgs[3]
Definition: test5.c:101
int test2e(struct Options options)
Definition: test5.c:1195
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:1387
int test8(struct Options options)
Definition: test5.c:2385
int test5c(struct Options options)
Definition: test5.c:1906
char * server_key_file
Definition: test3.c:84
char * client_key_file
Definition: test3.c:82
int test7OnUnsubscribed
Definition: test5.c:2112
void test3bOnConnectFailure(void *context, MQTTAsync_failureData *response)
Definition: test5.c:1423
void * test7_payload
Definition: test5.c:2099


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48