1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283
|
/*
Copyright (c) 2010-2020 Roger Light <roger@atchoo.org>
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
https://www.eclipse.org/legal/epl-2.0/
and the Eclipse Distribution License is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
Contributors:
Roger Light - initial implementation and documentation.
*/
#ifndef MOSQUITTO_H
#define MOSQUITTO_H
/*
* File: mosquitto.h
*
* This header contains functions and definitions for use with libmosquitto, the Mosquitto client library.
*
* The definitions are also used in Mosquitto broker plugins, and some functions are available to plugins.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WIN32
# ifdef mosquitto_EXPORTS
# define libmosq_EXPORT __declspec(dllexport)
# else
# ifndef LIBMOSQUITTO_STATIC
# ifdef libmosquitto_EXPORTS
# define libmosq_EXPORT __declspec(dllexport)
# else
# define libmosq_EXPORT __declspec(dllimport)
# endif
# else
# define libmosq_EXPORT
# endif
# endif
#else
# define libmosq_EXPORT
#endif
#if defined(_MSC_VER) && _MSC_VER < 1900 && !defined(bool)
# ifndef __cplusplus
# define bool char
# define true 1
# define false 0
# endif
#else
# ifndef __cplusplus
# include <stdbool.h>
# endif
#endif
#ifndef _MSC_VER
# define MOSQ_USED __attribute__((used))
#else
# define MOSQ_USED
#endif
#include <stddef.h>
#include <stdint.h>
#define LIBMOSQUITTO_MAJOR 2
#define LIBMOSQUITTO_MINOR 0
#define LIBMOSQUITTO_REVISION 22
/* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */
#define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION)
/* Log types */
#define MOSQ_LOG_NONE 0
#define MOSQ_LOG_INFO (1<<0)
#define MOSQ_LOG_NOTICE (1<<1)
#define MOSQ_LOG_WARNING (1<<2)
#define MOSQ_LOG_ERR (1<<3)
#define MOSQ_LOG_DEBUG (1<<4)
#define MOSQ_LOG_SUBSCRIBE (1<<5)
#define MOSQ_LOG_UNSUBSCRIBE (1<<6)
#define MOSQ_LOG_WEBSOCKETS (1<<7)
#define MOSQ_LOG_INTERNAL 0x80000000U
#define MOSQ_LOG_ALL 0xFFFFFFFFU
/* Enum: mosq_err_t
* Integer values returned from many libmosquitto functions. */
enum mosq_err_t {
MOSQ_ERR_AUTH_CONTINUE = -4,
MOSQ_ERR_NO_SUBSCRIBERS = -3,
MOSQ_ERR_SUB_EXISTS = -2,
MOSQ_ERR_CONN_PENDING = -1,
MOSQ_ERR_SUCCESS = 0,
MOSQ_ERR_NOMEM = 1,
MOSQ_ERR_PROTOCOL = 2,
MOSQ_ERR_INVAL = 3,
MOSQ_ERR_NO_CONN = 4,
MOSQ_ERR_CONN_REFUSED = 5,
MOSQ_ERR_NOT_FOUND = 6,
MOSQ_ERR_CONN_LOST = 7,
MOSQ_ERR_TLS = 8,
MOSQ_ERR_PAYLOAD_SIZE = 9,
MOSQ_ERR_NOT_SUPPORTED = 10,
MOSQ_ERR_AUTH = 11,
MOSQ_ERR_ACL_DENIED = 12,
MOSQ_ERR_UNKNOWN = 13,
MOSQ_ERR_ERRNO = 14,
MOSQ_ERR_EAI = 15,
MOSQ_ERR_PROXY = 16,
MOSQ_ERR_PLUGIN_DEFER = 17,
MOSQ_ERR_MALFORMED_UTF8 = 18,
MOSQ_ERR_KEEPALIVE = 19,
MOSQ_ERR_LOOKUP = 20,
MOSQ_ERR_MALFORMED_PACKET = 21,
MOSQ_ERR_DUPLICATE_PROPERTY = 22,
MOSQ_ERR_TLS_HANDSHAKE = 23,
MOSQ_ERR_QOS_NOT_SUPPORTED = 24,
MOSQ_ERR_OVERSIZE_PACKET = 25,
MOSQ_ERR_OCSP = 26,
MOSQ_ERR_TIMEOUT = 27,
MOSQ_ERR_RETAIN_NOT_SUPPORTED = 28,
MOSQ_ERR_TOPIC_ALIAS_INVALID = 29,
MOSQ_ERR_ADMINISTRATIVE_ACTION = 30,
MOSQ_ERR_ALREADY_EXISTS = 31,
};
/* Enum: mosq_opt_t
*
* Client options.
*
* See <mosquitto_int_option>, <mosquitto_string_option>, and <mosquitto_void_option>.
*/
enum mosq_opt_t {
MOSQ_OPT_PROTOCOL_VERSION = 1,
MOSQ_OPT_SSL_CTX = 2,
MOSQ_OPT_SSL_CTX_WITH_DEFAULTS = 3,
MOSQ_OPT_RECEIVE_MAXIMUM = 4,
MOSQ_OPT_SEND_MAXIMUM = 5,
MOSQ_OPT_TLS_KEYFORM = 6,
MOSQ_OPT_TLS_ENGINE = 7,
MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 = 8,
MOSQ_OPT_TLS_OCSP_REQUIRED = 9,
MOSQ_OPT_TLS_ALPN = 10,
MOSQ_OPT_TCP_NODELAY = 11,
MOSQ_OPT_BIND_ADDRESS = 12,
MOSQ_OPT_TLS_USE_OS_CERTS = 13,
};
/* MQTT specification restricts client ids to a maximum of 23 characters */
#define MOSQ_MQTT_ID_MAX_LENGTH 23
#define MQTT_PROTOCOL_V31 3
#define MQTT_PROTOCOL_V311 4
#define MQTT_PROTOCOL_V5 5
/* Struct: mosquitto_message
*
* Contains details of a PUBLISH message.
*
* int mid - the message/packet ID of the PUBLISH message, assuming this is a
* QoS 1 or 2 message. Will be set to 0 for QoS 0 messages.
*
* char *topic - the topic the message was delivered on.
*
* void *payload - the message payload. This will be payloadlen bytes long, and
* may be NULL if a zero length payload was sent.
*
* int payloadlen - the length of the payload, in bytes.
*
* int qos - the quality of service of the message, 0, 1, or 2.
*
* bool retain - set to true for stale retained messages.
*/
struct mosquitto_message{
int mid;
char *topic;
void *payload;
int payloadlen;
int qos;
bool retain;
};
struct mosquitto;
typedef struct mqtt5__property mosquitto_property;
/*
* Topic: Threads
* libmosquitto provides thread safe operation, with the exception of
* <mosquitto_lib_init> which is not thread safe.
*
* If the library has been compiled without thread support it is *not*
* guaranteed to be thread safe.
*
* If your application uses threads you must use <mosquitto_threaded_set> to
* tell the library this is the case, otherwise it makes some optimisations
* for the single threaded case that may result in unexpected behaviour for
* the multi threaded case.
*/
/***************************************************
* Important note
*
* The following functions that deal with network operations will return
* MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has
* taken place. An attempt will be made to write the network data, but if the
* socket is not available for writing at that time then the packet will not be
* sent. To ensure the packet is sent, call mosquitto_loop() (which must also
* be called to process incoming network data).
* This is especially important when disconnecting a client that has a will. If
* the broker does not receive the DISCONNECT command, it will assume that the
* client has disconnected unexpectedly and send the will.
*
* mosquitto_connect()
* mosquitto_disconnect()
* mosquitto_subscribe()
* mosquitto_unsubscribe()
* mosquitto_publish()
***************************************************/
/* ======================================================================
*
* Section: Library version, init, and cleanup
*
* ====================================================================== */
/*
* Function: mosquitto_lib_version
*
* Can be used to obtain version information for the mosquitto library.
* This allows the application to compare the library version against the
* version it was compiled against by using the LIBMOSQUITTO_MAJOR,
* LIBMOSQUITTO_MINOR and LIBMOSQUITTO_REVISION defines.
*
* Parameters:
* major - an integer pointer. If not NULL, the major version of the
* library will be returned in this variable.
* minor - an integer pointer. If not NULL, the minor version of the
* library will be returned in this variable.
* revision - an integer pointer. If not NULL, the revision of the library will
* be returned in this variable.
*
* Returns:
* LIBMOSQUITTO_VERSION_NUMBER - which is a unique number based on the major,
* minor and revision values.
* See Also:
* <mosquitto_lib_cleanup>, <mosquitto_lib_init>
*/
libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision);
/*
* Function: mosquitto_lib_init
*
* Must be called before any other mosquitto functions.
*
* This function is *not* thread safe.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_UNKNOWN - on Windows, if sockets couldn't be initialized.
*
* See Also:
* <mosquitto_lib_cleanup>, <mosquitto_lib_version>
*/
libmosq_EXPORT int mosquitto_lib_init(void);
/*
* Function: mosquitto_lib_cleanup
*
* Call to free resources associated with the library.
*
* Returns:
* MOSQ_ERR_SUCCESS - always
*
* See Also:
* <mosquitto_lib_init>, <mosquitto_lib_version>
*/
libmosq_EXPORT int mosquitto_lib_cleanup(void);
/* ======================================================================
*
* Section: Client creation, destruction, and reinitialisation
*
* ====================================================================== */
/*
* Function: mosquitto_new
*
* Create a new mosquitto client instance.
*
* Parameters:
* id - String to use as the client id. If NULL, a random client id
* will be generated. If id is NULL, clean_session must be true.
* clean_session - set to true to instruct the broker to clean all messages
* and subscriptions on disconnect, false to instruct it to
* keep them. See the man page mqtt(7) for more details.
* Note that a client will never discard its own outgoing
* messages on disconnect. Calling <mosquitto_connect> or
* <mosquitto_reconnect> will cause the messages to be resent.
* Use <mosquitto_reinitialise> to reset a client to its
* original state.
* Must be set to true if the id parameter is NULL.
* obj - A user pointer that will be passed as an argument to any
* callbacks that are specified.
*
* Returns:
* Pointer to a struct mosquitto on success.
* NULL on failure. Interrogate errno to determine the cause for the failure:
* - ENOMEM on out of memory.
* - EINVAL on invalid input parameters.
*
* See Also:
* <mosquitto_reinitialise>, <mosquitto_destroy>, <mosquitto_user_data_set>
*/
libmosq_EXPORT struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj);
/*
* Function: mosquitto_destroy
*
* Use to free memory associated with a mosquitto client instance.
*
* Parameters:
* mosq - a struct mosquitto pointer to free.
*
* See Also:
* <mosquitto_new>, <mosquitto_reinitialise>
*/
libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq);
/*
* Function: mosquitto_reinitialise
*
* This function allows an existing mosquitto client to be reused. Call on a
* mosquitto instance to close any open network connections, free memory
* and reinitialise the client with the new parameters. The end result is the
* same as the output of <mosquitto_new>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* id - string to use as the client id. If NULL, a random client id
* will be generated. If id is NULL, clean_session must be true.
* clean_session - set to true to instruct the broker to clean all messages
* and subscriptions on disconnect, false to instruct it to
* keep them. See the man page mqtt(7) for more details.
* Must be set to true if the id parameter is NULL.
* obj - A user pointer that will be passed as an argument to any
* callbacks that are specified.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_MALFORMED_UTF8 - if the client id is not valid UTF-8.
*
* See Also:
* <mosquitto_new>, <mosquitto_destroy>
*/
libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj);
/* ======================================================================
*
* Section: Will
*
* ====================================================================== */
/*
* Function: mosquitto_will_set
*
* Configure will information for a mosquitto instance. By default, clients do
* not have a will. This must be called before calling <mosquitto_connect>.
*
* It is valid to use this function for clients using all MQTT protocol versions.
* If you need to set MQTT v5 Will properties, use <mosquitto_will_set_v5> instead.
*
* Parameters:
* mosq - a valid mosquitto instance.
* topic - the topic on which to publish the will.
* payloadlen - the size of the payload (bytes). Valid values are between 0 and
* 268,435,455.
* payload - pointer to the data to send. If payloadlen > 0 this must be a
* valid memory location.
* qos - integer value 0, 1 or 2 indicating the Quality of Service to be
* used for the will.
* retain - set to true to make the will a retained message.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8.
*/
libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
/*
* Function: mosquitto_will_set_v5
*
* Configure will information for a mosquitto instance, with attached
* properties. By default, clients do not have a will. This must be called
* before calling <mosquitto_connect>.
*
* If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument
* will be applied to the Will.
*
* Set your client to use MQTT v5 immediately after it is created:
*
* mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
*
* Parameters:
* mosq - a valid mosquitto instance.
* topic - the topic on which to publish the will.
* payloadlen - the size of the payload (bytes). Valid values are between 0 and
* 268,435,455.
* payload - pointer to the data to send. If payloadlen > 0 this must be a
* valid memory location.
* qos - integer value 0, 1 or 2 indicating the Quality of Service to be
* used for the will.
* retain - set to true to make the will a retained message.
* properties - list of MQTT 5 properties. Can be NULL. On success only, the
* property list becomes the property of libmosquitto once this
* function is called and will be freed by the library. The
* property list must be freed by the application on error.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5
* MOSQ_ERR_PROTOCOL - if a property is invalid for use with wills.
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5.
*/
libmosq_EXPORT int mosquitto_will_set_v5(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties);
/*
* Function: mosquitto_will_clear
*
* Remove a previously configured will. This must be called before calling
* <mosquitto_connect>.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
*/
libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq);
/* ======================================================================
*
* Section: Username and password
*
* ====================================================================== */
/*
* Function: mosquitto_username_pw_set
*
* Configure username and password for a mosquitto instance. By default, no
* username or password will be sent. For v3.1 and v3.1.1 clients, if username
* is NULL, the password argument is ignored.
*
* This is must be called before calling <mosquitto_connect>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* username - the username to send as a string, or NULL to disable
* authentication.
* password - the password to send as a string. Set to NULL when username is
* valid in order to send just a username.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*/
libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password);
/* ======================================================================
*
* Section: Connecting, reconnecting, disconnecting
*
* ====================================================================== */
/*
* Function: mosquitto_connect
*
* Connect to an MQTT broker.
*
* It is valid to use this function for clients using all MQTT protocol versions.
* If you need to set MQTT v5 CONNECT properties, use <mosquitto_connect_bind_v5>
* instead.
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of:
* * mosq == NULL
* * host == NULL
* * port < 0
* * keepalive < 5 (keepalive == 0 is allowed, for an infinite keepalive)
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect_bind>, <mosquitto_connect_async>, <mosquitto_reconnect>, <mosquitto_disconnect>, <mosquitto_tls_set>
*/
libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive);
/*
* Function: mosquitto_connect_bind
*
* Connect to an MQTT broker. This extends the functionality of
* <mosquitto_connect> by adding the bind_address parameter. Use this function
* if you need to restrict network communication over a particular interface.
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to. If you do not want to bind to a specific interface,
* set this to NULL.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect>, <mosquitto_connect_async>, <mosquitto_connect_bind_async>
*/
libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);
/*
* Function: mosquitto_connect_bind_v5
*
* Connect to an MQTT broker. This extends the functionality of
* <mosquitto_connect> by adding the bind_address parameter and MQTT v5
* properties. Use this function if you need to restrict network communication
* over a particular interface.
*
* Use e.g. <mosquitto_property_add_string> and similar to create a list of
* properties, then attach them to this publish. Properties need freeing with
* <mosquitto_property_free_all>.
*
* If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument
* will be applied to the CONNECT message.
*
* Set your client to use MQTT v5 immediately after it is created:
*
* mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to. If you do not want to bind to a specific interface,
* set this to NULL.
* properties - the MQTT 5 properties for the connect (not for the Will).
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of:
* * mosq == NULL
* * host == NULL
* * port < 0
* * keepalive < 5 (keepalive == 0 is allowed, for an infinite keepalive)
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid for use with CONNECT.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5.
*
* See Also:
* <mosquitto_connect>, <mosquitto_connect_async>, <mosquitto_connect_bind_async>
*/
libmosq_EXPORT int mosquitto_connect_bind_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties);
/*
* Function: mosquitto_connect_async
*
* Connect to an MQTT broker. This is a non-blocking call. If you use
* <mosquitto_connect_async> your client must use the threaded interface
* <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
* <mosquitto_connect> to connect the client.
*
* May be called before or after <mosquitto_loop_start>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect_bind_async>, <mosquitto_connect>, <mosquitto_reconnect>, <mosquitto_disconnect>, <mosquitto_tls_set>
*/
libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive);
/*
* Function: mosquitto_connect_bind_async
*
* Connect to an MQTT broker. This is a non-blocking call. If you use
* <mosquitto_connect_bind_async> your client must use the threaded interface
* <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
* <mosquitto_connect> to connect the client.
*
* This extends the functionality of <mosquitto_connect_async> by adding the
* bind_address parameter. Use this function if you need to restrict network
* communication over a particular interface.
*
* May be called before or after <mosquitto_loop_start>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname or ip address of the broker to connect to.
* port - the network port to connect to. Usually 1883.
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to. If you do not want to bind to a specific interface,
* set this to NULL.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of:
* * mosq == NULL
* * host == NULL
* * port < 0
* * keepalive < 5
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect_async>, <mosquitto_connect>, <mosquitto_connect_bind>
*/
libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);
/*
* Function: mosquitto_connect_srv
*
* Connect to an MQTT broker.
*
* If you set `host` to `example.com`, then this call will attempt to retrieve
* the DNS SRV record for `_secure-mqtt._tcp.example.com` or
* `_mqtt._tcp.example.com` to discover which actual host to connect to.
*
* DNS SRV support is not usually compiled in to libmosquitto, use of this call
* is not recommended.
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the hostname to search for an SRV record.
* keepalive - the number of seconds after which the client should send a PING
* message to the broker if no other messages have been exchanged
* in that time.
* bind_address - the hostname or ip address of the local network interface to
* bind to. If you do not want to bind to a specific interface,
* set this to NULL.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid, which could be any of:
* * mosq == NULL
* * host == NULL
* * port < 0
* * keepalive < 5
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect_async>, <mosquitto_connect>, <mosquitto_connect_bind>
*/
libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address);
/*
* Function: mosquitto_reconnect
*
* Reconnect to a broker.
*
* This function provides an easy way of reconnecting to a broker after a
* connection has been lost. It uses the values that were provided in the
* <mosquitto_connect> call. It must not be called before
* <mosquitto_connect>.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect>, <mosquitto_disconnect>, <mosquitto_reconnect_async>
*/
libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq);
/*
* Function: mosquitto_reconnect_async
*
* Reconnect to a broker. Non blocking version of <mosquitto_reconnect>.
*
* This function provides an easy way of reconnecting to a broker after a
* connection has been lost. It uses the values that were provided in the
* <mosquitto_connect> or <mosquitto_connect_async> calls. It must not be
* called before <mosquitto_connect>.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_connect>, <mosquitto_disconnect>
*/
libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq);
/*
* Function: mosquitto_disconnect
*
* Disconnect from the broker.
*
* It is valid to use this function for clients using all MQTT protocol versions.
* If you need to set MQTT v5 DISCONNECT properties, use
* <mosquitto_disconnect_v5> instead.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
*/
libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq);
/*
* Function: mosquitto_disconnect_v5
*
* Disconnect from the broker, with attached MQTT properties.
*
* Use e.g. <mosquitto_property_add_string> and similar to create a list of
* properties, then attach them to this publish. Properties need freeing with
* <mosquitto_property_free_all>.
*
* If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument
* will be applied to the DISCONNECT message.
*
* Set your client to use MQTT v5 immediately after it is created:
*
* mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
*
* Parameters:
* mosq - a valid mosquitto instance.
* reason_code - the disconnect reason code.
* properties - a valid mosquitto_property list, or NULL.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid for use with DISCONNECT.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5.
*/
libmosq_EXPORT int mosquitto_disconnect_v5(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties);
/* ======================================================================
*
* Section: Publishing, subscribing, unsubscribing
*
* ====================================================================== */
/*
* Function: mosquitto_publish
*
* Publish a message on a given topic.
*
* It is valid to use this function for clients using all MQTT protocol versions.
* If you need to set MQTT v5 PUBLISH properties, use <mosquitto_publish_v5>
* instead.
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - pointer to an int. If not NULL, the function will set this
* to the message id of this particular message. This can be then
* used with the publish callback to determine when the message
* has been sent.
* Note that although the MQTT protocol doesn't use message ids
* for messages with QoS=0, libmosquitto assigns them message ids
* so they can be tracked with this parameter.
* topic - null terminated string of the topic to publish to.
* payloadlen - the size of the payload (bytes). Valid values are between 0 and
* 268,435,455.
* payload - pointer to the data to send. If payloadlen > 0 this must be a
* valid memory location.
* qos - integer value 0, 1 or 2 indicating the Quality of Service to be
* used for the message.
* retain - set to true to make the message retained.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
* broker.
* MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
* MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by
* the broker.
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*
* See Also:
* <mosquitto_max_inflight_messages_set>
*/
libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
/*
* Function: mosquitto_publish_v5
*
* Publish a message on a given topic, with attached MQTT properties.
*
* Use e.g. <mosquitto_property_add_string> and similar to create a list of
* properties, then attach them to this publish. Properties need freeing with
* <mosquitto_property_free_all>.
*
* If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument
* will be applied to the PUBLISH message.
*
* Set your client to use MQTT v5 immediately after it is created:
*
* mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - pointer to an int. If not NULL, the function will set this
* to the message id of this particular message. This can be then
* used with the publish callback to determine when the message
* has been sent.
* Note that although the MQTT protocol doesn't use message ids
* for messages with QoS=0, libmosquitto assigns them message ids
* so they can be tracked with this parameter.
* topic - null terminated string of the topic to publish to.
* payloadlen - the size of the payload (bytes). Valid values are between 0 and
* 268,435,455.
* payload - pointer to the data to send. If payloadlen > 0 this must be a
* valid memory location.
* qos - integer value 0, 1 or 2 indicating the Quality of Service to be
* used for the message.
* retain - set to true to make the message retained.
* properties - a valid mosquitto_property list, or NULL.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
* broker.
* MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid for use with PUBLISH.
* MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by
* the broker.
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5.
*/
libmosq_EXPORT int mosquitto_publish_v5(
struct mosquitto *mosq,
int *mid,
const char *topic,
int payloadlen,
const void *payload,
int qos,
bool retain,
const mosquitto_property *properties);
/*
* Function: mosquitto_subscribe
*
* Subscribe to a topic.
*
* It is valid to use this function for clients using all MQTT protocol versions.
* If you need to set MQTT v5 SUBSCRIBE properties, use <mosquitto_subscribe_v5>
* instead.
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the subscribe callback to determine when the message has been
* sent.
* sub - the subscription pattern.
* qos - the requested Quality of Service for this subscription.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*/
libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos);
/*
* Function: mosquitto_subscribe_v5
*
* Subscribe to a topic, with attached MQTT properties.
*
* Use e.g. <mosquitto_property_add_string> and similar to create a list of
* properties, then attach them to this publish. Properties need freeing with
* <mosquitto_property_free_all>.
*
* If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument
* will be applied to the PUBLISH message.
*
* Set your client to use MQTT v5 immediately after it is created:
*
* mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the subscribe callback to determine when the message has been
* sent.
* sub - the subscription pattern.
* qos - the requested Quality of Service for this subscription.
* options - options to apply to this subscription, OR'd together. Set to 0 to
* use the default options, otherwise choose from list of <mqtt5_sub_options>
* properties - a valid mosquitto_property list, or NULL.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid for use with SUBSCRIBE.
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5.
*/
libmosq_EXPORT int mosquitto_subscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, int qos, int options, const mosquitto_property *properties);
/*
* Function: mosquitto_subscribe_multiple
*
* Subscribe to multiple topics.
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the subscribe callback to determine when the message has been
* sent.
* sub_count - the count of subscriptions to be made
* sub - array of sub_count pointers, each pointing to a subscription string.
* The "char *const *const" datatype ensures that neither the array of
* pointers nor the strings that they point to are mutable. If you aren't
* familiar with this, just think of it as a safer "char **",
* equivalent to "const char *" for a simple string pointer.
* qos - the requested Quality of Service for each subscription.
* options - options to apply to this subscription, OR'd together. This
* argument is not used for MQTT v3 susbcriptions. Set to 0 to use
* the default options, otherwise choose from list of <mqtt5_sub_options>
* properties - a valid mosquitto_property list, or NULL. Only used with MQTT
* v5 clients.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if a topic is not valid UTF-8
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*/
libmosq_EXPORT int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos, int options, const mosquitto_property *properties);
/*
* Function: mosquitto_unsubscribe
*
* Unsubscribe from a topic.
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the unsubscribe callback to determine when the message has been
* sent.
* sub - the unsubscription pattern.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*/
libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub);
/*
* Function: mosquitto_unsubscribe_v5
*
* Unsubscribe from a topic, with attached MQTT properties.
*
* It is valid to use this function for clients using all MQTT protocol versions.
* If you need to set MQTT v5 UNSUBSCRIBE properties, use
* <mosquitto_unsubscribe_v5> instead.
*
* Use e.g. <mosquitto_property_add_string> and similar to create a list of
* properties, then attach them to this publish. Properties need freeing with
* <mosquitto_property_free_all>.
*
* If the mosquitto instance `mosq` is using MQTT v5, the `properties` argument
* will be applied to the PUBLISH message.
*
* Set your client to use MQTT v5 immediately after it is created:
*
* mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the unsubscribe callback to determine when the message has been
* sent.
* sub - the unsubscription pattern.
* properties - a valid mosquitto_property list, or NULL. Only used with MQTT
* v5 clients.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid for use with UNSUBSCRIBE.
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
* MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
* using MQTT v5.
*/
libmosq_EXPORT int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties);
/*
* Function: mosquitto_unsubscribe_multiple
*
* Unsubscribe from multiple topics.
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the subscribe callback to determine when the message has been
* sent.
* sub_count - the count of unsubscriptions to be made
* sub - array of sub_count pointers, each pointing to an unsubscription string.
* The "char *const *const" datatype ensures that neither the array of
* pointers nor the strings that they point to are mutable. If you aren't
* familiar with this, just think of it as a safer "char **",
* equivalent to "const char *" for a simple string pointer.
* properties - a valid mosquitto_property list, or NULL. Only used with MQTT
* v5 clients.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if a topic is not valid UTF-8
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*/
libmosq_EXPORT int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties);
/* ======================================================================
*
* Section: Struct mosquitto_message helper functions
*
* ====================================================================== */
/*
* Function: mosquitto_message_copy
*
* Copy the contents of a mosquitto message to another message.
* Useful for preserving a message received in the on_message() callback.
*
* Parameters:
* dst - a pointer to a valid mosquitto_message struct to copy to.
* src - a pointer to a valid mosquitto_message struct to copy from.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*
* See Also:
* <mosquitto_message_free>
*/
libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, const struct mosquitto_message *src);
/*
* Function: mosquitto_message_free
*
* Completely free a mosquitto_message struct.
*
* Parameters:
* message - pointer to a mosquitto_message pointer to free.
*
* See Also:
* <mosquitto_message_copy>, <mosquitto_message_free_contents>
*/
libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message);
/*
* Function: mosquitto_message_free_contents
*
* Free a mosquitto_message struct contents, leaving the struct unaffected.
*
* Parameters:
* message - pointer to a mosquitto_message struct to free its contents.
*
* See Also:
* <mosquitto_message_copy>, <mosquitto_message_free>
*/
libmosq_EXPORT void mosquitto_message_free_contents(struct mosquitto_message *message);
/* ======================================================================
*
* Section: Network loop (managed by libmosquitto)
*
* The internal network loop must be called at a regular interval. The two
* recommended approaches are to use either <mosquitto_loop_forever> or
* <mosquitto_loop_start>. <mosquitto_loop_forever> is a blocking call and is
* suitable for the situation where you only want to handle incoming messages
* in callbacks. <mosquitto_loop_start> is a non-blocking call, it creates a
* separate thread to run the loop for you. Use this function when you have
* other tasks you need to run at the same time as the MQTT client, e.g.
* reading data from a sensor.
*
* ====================================================================== */
/*
* Function: mosquitto_loop_forever
*
* This function call loop() for you in an infinite blocking loop. It is useful
* for the case where you only want to run the MQTT client loop in your
* program.
*
* It handles reconnecting in case server connection is lost. If you call
* mosquitto_disconnect() in a callback it will return.
*
* Parameters:
* mosq - a valid mosquitto instance.
* timeout - Maximum number of milliseconds to wait for network activity
* in the select() call before timing out. Set to 0 for instant
* return. Set negative to use the default of 1000ms.
* max_packets - this parameter is currently unused and should be set to 1 for
* future compatibility.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
* MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
* broker.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_loop>, <mosquitto_loop_start>
*/
libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets);
/*
* Function: mosquitto_loop_start
*
* This is part of the threaded client interface. Call this once to start a new
* thread to process network traffic. This provides an alternative to
* repeatedly calling <mosquitto_loop> yourself.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOT_SUPPORTED - if thread support is not available.
*
* See Also:
* <mosquitto_connect_async>, <mosquitto_loop>, <mosquitto_loop_forever>, <mosquitto_loop_stop>
*/
libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq);
/*
* Function: mosquitto_loop_stop
*
* This is part of the threaded client interface. Call this once to stop the
* network thread previously created with <mosquitto_loop_start>. This call
* will block until the network thread finishes. For the network thread to end,
* you must have previously called <mosquitto_disconnect> or have set the force
* parameter to true.
*
* Parameters:
* mosq - a valid mosquitto instance.
* force - set to true to force thread cancellation. If false,
* <mosquitto_disconnect> must have already been called.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOT_SUPPORTED - if thread support is not available.
*
* See Also:
* <mosquitto_loop>, <mosquitto_loop_start>
*/
libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force);
/*
* Function: mosquitto_loop
*
* The main network loop for the client. This must be called frequently
* to keep communications between the client and broker working. This is
* carried out by <mosquitto_loop_forever> and <mosquitto_loop_start>, which
* are the recommended ways of handling the network loop. You may also use this
* function if you wish. It must not be called inside a callback.
*
* If incoming data is present it will then be processed. Outgoing commands,
* from e.g. <mosquitto_publish>, are normally sent immediately that their
* function is called, but this is not always possible. <mosquitto_loop> will
* also attempt to send any remaining outgoing messages, which also includes
* commands that are part of the flow for messages with QoS>0.
*
* This calls select() to monitor the client network socket. If you want to
* integrate mosquitto client operation with your own select() call, use
* <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write> and
* <mosquitto_loop_misc>.
*
* Threads:
*
* Parameters:
* mosq - a valid mosquitto instance.
* timeout - Maximum number of milliseconds to wait for network activity
* in the select() call before timing out. Set to 0 for instant
* return. Set negative to use the default of 1000ms.
* max_packets - this parameter is currently unused and should be set to 1 for
* future compatibility.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
* MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
* broker.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
* See Also:
* <mosquitto_loop_forever>, <mosquitto_loop_start>, <mosquitto_loop_stop>
*/
libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets);
/* ======================================================================
*
* Section: Network loop (for use in other event loops)
*
* ====================================================================== */
/*
* Function: mosquitto_loop_read
*
* Carry out network read operations.
* This should only be used if you are not using mosquitto_loop() and are
* monitoring the client network socket for activity yourself.
*
* Parameters:
* mosq - a valid mosquitto instance.
* max_packets - this parameter is currently unused and should be set to 1 for
* future compatibility.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
* MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
* broker.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_socket>, <mosquitto_loop_write>, <mosquitto_loop_misc>
*/
libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets);
/*
* Function: mosquitto_loop_write
*
* Carry out network write operations.
* This should only be used if you are not using mosquitto_loop() and are
* monitoring the client network socket for activity yourself.
*
* Parameters:
* mosq - a valid mosquitto instance.
* max_packets - this parameter is currently unused and should be set to 1 for
* future compatibility.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
* MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
* broker.
* MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
* contains the error code, even on Windows.
* Use strerror_r() where available or FormatMessage() on
* Windows.
*
* See Also:
* <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_misc>, <mosquitto_want_write>
*/
libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets);
/*
* Function: mosquitto_loop_misc
*
* Carry out miscellaneous operations required as part of the network loop.
* This should only be used if you are not using mosquitto_loop() and are
* monitoring the client network socket for activity yourself.
*
* This function deals with handling PINGs and checking whether messages need
* to be retried, so should be called fairly frequently, around once per second
* is sufficient.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
*
* See Also:
* <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write>
*/
libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq);
/* ======================================================================
*
* Section: Network loop (helper functions)
*
* ====================================================================== */
/*
* Function: mosquitto_socket
*
* Return the socket handle for a mosquitto instance. Useful if you want to
* include a mosquitto client in your own select() calls.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* The socket for the mosquitto client or -1 on failure.
*/
libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq);
/*
* Function: mosquitto_want_write
*
* Returns true if there is data ready to be written on the socket.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* See Also:
* <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write>
*/
libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq);
/*
* Function: mosquitto_threaded_set
*
* Used to tell the library that your application is using threads, but not
* using <mosquitto_loop_start>. The library operates slightly differently when
* not in threaded mode in order to simplify its operation. If you are managing
* your own threads and do not use this function you will experience crashes
* due to race conditions.
*
* When using <mosquitto_loop_start>, this is set automatically.
*
* Parameters:
* mosq - a valid mosquitto instance.
* threaded - true if your application is using threads, false otherwise.
*/
libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded);
/* ======================================================================
*
* Section: Client options
*
* ====================================================================== */
/*
* Function: mosquitto_opts_set
*
* Used to set options for the client.
*
* This function is deprecated, the replacement <mosquitto_int_option>,
* <mosquitto_string_option> and <mosquitto_void_option> functions should
* be used instead.
*
* Parameters:
* mosq - a valid mosquitto instance.
* option - the option to set.
* value - the option specific value.
*
* Options:
* MOSQ_OPT_PROTOCOL_VERSION - Value must be an int, set to either
* MQTT_PROTOCOL_V31 or MQTT_PROTOCOL_V311. Must be set
* before the client connects.
* Defaults to MQTT_PROTOCOL_V31.
*
* MOSQ_OPT_SSL_CTX - Pass an openssl SSL_CTX to be used when creating
* TLS connections rather than libmosquitto creating its own.
* This must be called before connecting to have any effect.
* If you use this option, the onus is on you to ensure that
* you are using secure settings.
* Setting to NULL means that libmosquitto will use its own SSL_CTX
* if TLS is to be used.
* This option is only available for openssl 1.1.0 and higher.
*
* MOSQ_OPT_SSL_CTX_WITH_DEFAULTS - Value must be an int set to 1 or 0.
* If set to 1, then the user specified SSL_CTX passed in using
* MOSQ_OPT_SSL_CTX will have the default options applied to it.
* This means that you only need to change the values that are
* relevant to you. If you use this option then you must configure
* the TLS options as normal, i.e. you should use
* <mosquitto_tls_set> to configure the cafile/capath as a minimum.
* This option is only available for openssl 1.1.0 and higher.
*/
libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value);
/*
* Function: mosquitto_int_option
*
* Used to set integer options for the client.
*
* Parameters:
* mosq - a valid mosquitto instance.
* option - the option to set.
* value - the option specific value.
*
* Options:
* MOSQ_OPT_TCP_NODELAY - Set to 1 to disable Nagle's algorithm on client
* sockets. This has the effect of reducing latency of individual
* messages at the potential cost of increasing the number of
* packets being sent.
* Defaults to 0, which means Nagle remains enabled.
*
* MOSQ_OPT_PROTOCOL_VERSION - Value must be set to either MQTT_PROTOCOL_V31,
* MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the
* client connects. Defaults to MQTT_PROTOCOL_V311.
*
* MOSQ_OPT_RECEIVE_MAXIMUM - Value can be set between 1 and 65535 inclusive,
* and represents the maximum number of incoming QoS 1 and QoS 2
* messages that this client wants to process at once. Defaults to
* 20. This option is not valid for MQTT v3.1 or v3.1.1 clients.
* Note that if the MQTT_PROP_RECEIVE_MAXIMUM property is in the
* proplist passed to mosquitto_connect_v5(), then that property
* will override this option. Using this option is the recommended
* method however.
*
* MOSQ_OPT_SEND_MAXIMUM - Value can be set between 1 and 65535 inclusive,
* and represents the maximum number of outgoing QoS 1 and QoS 2
* messages that this client will attempt to have "in flight" at
* once. Defaults to 20.
* This option is not valid for MQTT v3.1 or v3.1.1 clients.
* Note that if the broker being connected to sends a
* MQTT_PROP_RECEIVE_MAXIMUM property that has a lower value than
* this option, then the broker provided value will be used.
*
* MOSQ_OPT_SSL_CTX_WITH_DEFAULTS - If value is set to a non zero value,
* then the user specified SSL_CTX passed in using MOSQ_OPT_SSL_CTX
* will have the default options applied to it. This means that
* you only need to change the values that are relevant to you.
* If you use this option then you must configure the TLS options
* as normal, i.e. you should use <mosquitto_tls_set> to
* configure the cafile/capath as a minimum.
* This option is only available for openssl 1.1.0 and higher.
*
* MOSQ_OPT_TLS_OCSP_REQUIRED - Set whether OCSP checking on TLS
* connections is required. Set to 1 to enable checking,
* or 0 (the default) for no checking.
*
* MOSQ_OPT_TLS_USE_OS_CERTS - Set to 1 to instruct the client to load and
* trust OS provided CA certificates for use with TLS connections.
* Set to 0 (the default) to only use manually specified CA certs.
*/
libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value);
/*
* Function: mosquitto_string_option
*
* Used to set const char* options for the client.
*
* Parameters:
* mosq - a valid mosquitto instance.
* option - the option to set.
* value - the option specific value.
*
* Options:
* MOSQ_OPT_TLS_ENGINE - Configure the client for TLS Engine support.
* Pass a TLS Engine ID to be used when creating TLS
* connections. Must be set before <mosquitto_connect>.
* Must be a valid engine, and note that the string will not be used
* until a connection attempt is made so this function will return
* success even if an invalid engine string is passed.
*
* MOSQ_OPT_TLS_KEYFORM - Configure the client to treat the keyfile
* differently depending on its type. Must be set
* before <mosquitto_connect>.
* Set as either "pem" or "engine", to determine from where the
* private key for a TLS connection will be obtained. Defaults to
* "pem", a normal private key file.
*
* MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 - Where the TLS Engine requires the use of
* a password to be accessed, this option allows a hex encoded
* SHA1 hash of the private key password to be passed to the
* engine directly. Must be set before <mosquitto_connect>.
*
* MOSQ_OPT_TLS_ALPN - If the broker being connected to has multiple
* services available on a single TLS port, such as both MQTT
* and WebSockets, use this option to configure the ALPN
* option for the connection.
*
* MOSQ_OPT_BIND_ADDRESS - Set the hostname or ip address of the local network
* interface to bind to when connecting.
*/
libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value);
/*
* Function: mosquitto_void_option
*
* Used to set void* options for the client.
*
* Parameters:
* mosq - a valid mosquitto instance.
* option - the option to set.
* value - the option specific value.
*
* Options:
* MOSQ_OPT_SSL_CTX - Pass an openssl SSL_CTX to be used when creating TLS
* connections rather than libmosquitto creating its own. This must
* be called before connecting to have any effect. If you use this
* option, the onus is on you to ensure that you are using secure
* settings.
* Setting to NULL means that libmosquitto will use its own SSL_CTX
* if TLS is to be used.
* This option is only available for openssl 1.1.0 and higher.
*/
libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value);
/*
* Function: mosquitto_reconnect_delay_set
*
* Control the behaviour of the client when it has unexpectedly disconnected in
* <mosquitto_loop_forever> or after <mosquitto_loop_start>. The default
* behaviour if this function is not used is to repeatedly attempt to reconnect
* with a delay of 1 second until the connection succeeds.
*
* Use reconnect_delay parameter to change the delay between successive
* reconnection attempts. You may also enable exponential backoff of the time
* between reconnections by setting reconnect_exponential_backoff to true and
* set an upper bound on the delay with reconnect_delay_max.
*
* Example 1:
* delay=2, delay_max=10, exponential_backoff=False
* Delays would be: 2, 4, 6, 8, 10, 10, ...
*
* Example 2:
* delay=3, delay_max=30, exponential_backoff=True
* Delays would be: 3, 6, 12, 24, 30, 30, ...
*
* Parameters:
* mosq - a valid mosquitto instance.
* reconnect_delay - the number of seconds to wait between
* reconnects.
* reconnect_delay_max - the maximum number of seconds to wait
* between reconnects.
* reconnect_exponential_backoff - use exponential backoff between
* reconnect attempts. Set to true to enable
* exponential backoff.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
*/
libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff);
/*
* Function: mosquitto_max_inflight_messages_set
*
* This function is deprected. Use the <mosquitto_int_option> function with the
* MOSQ_OPT_SEND_MAXIMUM option instead.
*
* Set the number of QoS 1 and 2 messages that can be "in flight" at one time.
* An in flight message is part way through its delivery flow. Attempts to send
* further messages with <mosquitto_publish> will result in the messages being
* queued until the number of in flight messages reduces.
*
* A higher number here results in greater message throughput, but if set
* higher than the maximum in flight messages on the broker may lead to
* delays in the messages being acknowledged.
*
* Set to 0 for no maximum.
*
* Parameters:
* mosq - a valid mosquitto instance.
* max_inflight_messages - the maximum number of inflight messages. Defaults
* to 20.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
*/
libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, unsigned int max_inflight_messages);
/*
* Function: mosquitto_message_retry_set
*
* This function now has no effect.
*/
libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned int message_retry);
/*
* Function: mosquitto_user_data_set
*
* When <mosquitto_new> is called, the pointer given as the "obj" parameter
* will be passed to the callbacks as user data. The <mosquitto_user_data_set>
* function allows this obj parameter to be updated at any time. This function
* will not modify the memory pointed to by the current user data pointer. If
* it is dynamically allocated memory you must free it yourself.
*
* Parameters:
* mosq - a valid mosquitto instance.
* obj - A user pointer that will be passed as an argument to any callbacks
* that are specified.
*/
libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj);
/* Function: mosquitto_userdata
*
* Retrieve the "userdata" variable for a mosquitto client.
*
* Parameters:
* mosq - a valid mosquitto instance.
*
* Returns:
* A pointer to the userdata member variable.
*/
libmosq_EXPORT void *mosquitto_userdata(struct mosquitto *mosq);
/* ======================================================================
*
* Section: TLS support
*
* ====================================================================== */
/*
* Function: mosquitto_tls_set
*
* Configure the client for certificate based SSL/TLS support. Must be called
* before <mosquitto_connect>.
*
* Cannot be used in conjunction with <mosquitto_tls_psk_set>.
*
* Define the Certificate Authority certificates to be trusted (ie. the server
* certificate must be signed with one of these certificates) using cafile.
*
* If the server you are connecting to requires clients to provide a
* certificate, define certfile and keyfile with your client certificate and
* private key. If your private key is encrypted, provide a password callback
* function or you will have to enter the password at the command line.
*
* Parameters:
* mosq - a valid mosquitto instance.
* cafile - path to a file containing the PEM encoded trusted CA
* certificate files. Either cafile or capath must not be NULL.
* capath - path to a directory containing the PEM encoded trusted CA
* certificate files. See mosquitto.conf for more details on
* configuring this directory. Either cafile or capath must not
* be NULL.
* certfile - path to a file containing the PEM encoded certificate file
* for this client. If NULL, keyfile must also be NULL and no
* client certificate will be used.
* keyfile - path to a file containing the PEM encoded private key for
* this client. If NULL, certfile must also be NULL and no
* client certificate will be used.
* pw_callback - if keyfile is encrypted, set pw_callback to allow your client
* to pass the correct password for decryption. If set to NULL,
* the password must be entered on the command line.
* Your callback must write the password into "buf", which is
* "size" bytes long. The return value must be the length of the
* password. "userdata" will be set to the calling mosquitto
* instance. The mosquitto userdata member variable can be
* retrieved using <mosquitto_userdata>.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*
* See Also:
* <mosquitto_tls_opts_set>, <mosquitto_tls_psk_set>,
* <mosquitto_tls_insecure_set>, <mosquitto_userdata>
*/
libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq,
const char *cafile, const char *capath,
const char *certfile, const char *keyfile,
int (*pw_callback)(char *buf, int size, int rwflag, void *userdata));
/*
* Function: mosquitto_tls_insecure_set
*
* Configure verification of the server hostname in the server certificate. If
* value is set to true, it is impossible to guarantee that the host you are
* connecting to is not impersonating your server. This can be useful in
* initial server testing, but makes it possible for a malicious third party to
* impersonate your server through DNS spoofing, for example.
* Do not use this function in a real system. Setting value to true makes the
* connection encryption pointless.
* Must be called before <mosquitto_connect>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* value - if set to false, the default, certificate hostname checking is
* performed. If set to true, no hostname checking is performed and
* the connection is insecure.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
*
* See Also:
* <mosquitto_tls_set>
*/
libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value);
/*
* Function: mosquitto_tls_opts_set
*
* Set advanced SSL/TLS options. Must be called before <mosquitto_connect>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* cert_reqs - an integer defining the verification requirements the client
* will impose on the server. This can be one of:
* * SSL_VERIFY_NONE (0): the server will not be verified in any way.
* * SSL_VERIFY_PEER (1): the server certificate will be verified
* and the connection aborted if the verification fails.
* The default and recommended value is SSL_VERIFY_PEER. Using
* SSL_VERIFY_NONE provides no security.
* tls_version - the version of the SSL/TLS protocol to use as a string. If NULL,
* the default value is used. The default value and the
* available values depend on the version of openssl that the
* library was compiled against. For openssl >= 1.0.1, the
* available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2
* as the default. For openssl < 1.0.1, only tlsv1 is available.
* ciphers - a string describing the ciphers available for use. See the
* "openssl ciphers" tool for more information. If NULL, the
* default ciphers will be used.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*
* See Also:
* <mosquitto_tls_set>
*/
libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, const char *tls_version, const char *ciphers);
/*
* Function: mosquitto_tls_psk_set
*
* Configure the client for pre-shared-key based TLS support. Must be called
* before <mosquitto_connect>.
*
* Cannot be used in conjunction with <mosquitto_tls_set>.
*
* Parameters:
* mosq - a valid mosquitto instance.
* psk - the pre-shared-key in hex format with no leading "0x".
* identity - the identity of this client. May be used as the username
* depending on the server settings.
* ciphers - a string describing the PSK ciphers available for use. See the
* "openssl ciphers" tool for more information. If NULL, the
* default ciphers will be used.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*
* See Also:
* <mosquitto_tls_set>
*/
libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers);
/*
* Function: mosquitto_ssl_get
*
* Retrieve a pointer to the SSL structure used for TLS connections in this
* client. This can be used in e.g. the connect callback to carry out
* additional verification steps.
*
* Parameters:
* mosq - a valid mosquitto instance
*
* Returns:
* A valid pointer to an openssl SSL structure - if the client is using TLS.
* NULL - if the client is not using TLS, or TLS support is not compiled in.
*/
libmosq_EXPORT void *mosquitto_ssl_get(struct mosquitto *mosq);
/* ======================================================================
*
* Section: Callbacks
*
* ====================================================================== */
/*
* Function: mosquitto_connect_callback_set
*
* Set the connect callback. This is called when the library receives a CONNACK
* message in response to a connection.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_connect - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int rc)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* rc - the return code of the connection response. The values are defined by
* the MQTT protocol version in use.
* For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
* For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
*/
libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int));
/*
* Function: mosquitto_connect_with_flags_callback_set
*
* Set the connect callback. This is called when the library receives a CONNACK
* message in response to a connection.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_connect - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int rc)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* rc - the return code of the connection response. The values are defined by
* the MQTT protocol version in use.
* For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
* For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
* flags - the connect flags.
*/
libmosq_EXPORT void mosquitto_connect_with_flags_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int));
/*
* Function: mosquitto_connect_v5_callback_set
*
* Set the connect callback. This is called when the library receives a CONNACK
* message in response to a connection.
*
* It is valid to set this callback for all MQTT protocol versions. If it is
* used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props`
* argument will always be NULL.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_connect - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int rc)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* rc - the return code of the connection response. The values are defined by
* the MQTT protocol version in use.
* For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
* For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
* flags - the connect flags.
* props - list of MQTT 5 properties, or NULL
*
*/
libmosq_EXPORT void mosquitto_connect_v5_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int, const mosquitto_property *props));
/*
* Function: mosquitto_disconnect_callback_set
*
* Set the disconnect callback. This is called when the broker has received the
* DISCONNECT command and has disconnected the client.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_disconnect - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* rc - integer value indicating the reason for the disconnect. A value of 0
* means the client has called <mosquitto_disconnect>. Any other value
* indicates that the disconnect is unexpected.
*/
libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int));
/*
* Function: mosquitto_disconnect_v5_callback_set
*
* Set the disconnect callback. This is called when the broker has received the
* DISCONNECT command and has disconnected the client.
*
* It is valid to set this callback for all MQTT protocol versions. If it is
* used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props`
* argument will always be NULL.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_disconnect - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* rc - integer value indicating the reason for the disconnect. A value of 0
* means the client has called <mosquitto_disconnect>. Any other value
* indicates that the disconnect is unexpected.
* props - list of MQTT 5 properties, or NULL
*/
libmosq_EXPORT void mosquitto_disconnect_v5_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int, const mosquitto_property *props));
/*
* Function: mosquitto_publish_callback_set
*
* Set the publish callback. This is called when a message initiated with
* <mosquitto_publish> has been sent to the broker. "Sent" means different
* things depending on the QoS of the message:
*
* QoS 0: The PUBLISH was passed to the local operating system for delivery,
* there is no guarantee that it was delivered to the remote broker.
* QoS 1: The PUBLISH was sent to the remote broker and the corresponding
* PUBACK was received by the library.
* QoS 2: The PUBLISH was sent to the remote broker and the corresponding
* PUBCOMP was received by the library.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_publish - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the sent message.
*/
libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int));
/*
* Function: mosquitto_publish_v5_callback_set
*
* Set the publish callback. This is called when a message initiated with
* <mosquitto_publish> has been sent to the broker. This callback will be
* called both if the message is sent successfully, or if the broker responded
* with an error, which will be reflected in the reason_code parameter.
* "Sent" means different things depending on the QoS of the message:
*
* QoS 0: The PUBLISH was passed to the local operating system for delivery,
* there is no guarantee that it was delivered to the remote broker.
* QoS 1: The PUBLISH was sent to the remote broker and the corresponding
* PUBACK was received by the library.
* QoS 2: The PUBLISH was sent to the remote broker and the corresponding
* PUBCOMP was received by the library.
*
*
* It is valid to set this callback for all MQTT protocol versions. If it is
* used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props`
* argument will always be NULL.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_publish - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the sent message.
* reason_code - the MQTT 5 reason code
* props - list of MQTT 5 properties, or NULL
*/
libmosq_EXPORT void mosquitto_publish_v5_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int, int, const mosquitto_property *props));
/*
* Function: mosquitto_message_callback_set
*
* Set the message callback. This is called when a message is received from the
* broker and the required QoS flow has completed.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_message - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* message - the message data. This variable and associated memory will be
* freed by the library after the callback completes. The client
* should make copies of any of the data it requires.
*
* See Also:
* <mosquitto_message_copy>
*/
libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *));
/*
* Function: mosquitto_message_v5_callback_set
*
* Set the message callback. This is called when a message is received from the
* broker and the required QoS flow has completed.
*
* It is valid to set this callback for all MQTT protocol versions. If it is
* used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props`
* argument will always be NULL.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_message - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* message - the message data. This variable and associated memory will be
* freed by the library after the callback completes. The client
* should make copies of any of the data it requires.
* props - list of MQTT 5 properties, or NULL
*
* See Also:
* <mosquitto_message_copy>
*/
libmosq_EXPORT void mosquitto_message_v5_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *, const mosquitto_property *props));
/*
* Function: mosquitto_subscribe_callback_set
*
* Set the subscribe callback. This is called when the library receives a
* SUBACK message in response to a SUBSCRIBE.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_subscribe - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the subscribe message.
* qos_count - the number of granted subscriptions (size of granted_qos).
* granted_qos - an array of integers indicating the granted QoS for each of
* the subscriptions.
*/
libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *));
/*
* Function: mosquitto_subscribe_v5_callback_set
*
* Set the subscribe callback. This is called when the library receives a
* SUBACK message in response to a SUBSCRIBE.
*
* It is valid to set this callback for all MQTT protocol versions. If it is
* used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props`
* argument will always be NULL.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_subscribe - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the subscribe message.
* qos_count - the number of granted subscriptions (size of granted_qos).
* granted_qos - an array of integers indicating the granted QoS for each of
* the subscriptions.
* props - list of MQTT 5 properties, or NULL
*/
libmosq_EXPORT void mosquitto_subscribe_v5_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *props));
/*
* Function: mosquitto_unsubscribe_callback_set
*
* Set the unsubscribe callback. This is called when the library receives a
* UNSUBACK message in response to an UNSUBSCRIBE.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_unsubscribe - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the unsubscribe message.
*/
libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int));
/*
* Function: mosquitto_unsubscribe_v5_callback_set
*
* Set the unsubscribe callback. This is called when the library receives a
* UNSUBACK message in response to an UNSUBSCRIBE.
*
* It is valid to set this callback for all MQTT protocol versions. If it is
* used with MQTT clients that use MQTT v3.1.1 or earlier, then the `props`
* argument will always be NULL.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_unsubscribe - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the unsubscribe message.
* props - list of MQTT 5 properties, or NULL
*/
libmosq_EXPORT void mosquitto_unsubscribe_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, const mosquitto_property *props));
/*
* Function: mosquitto_log_callback_set
*
* Set the logging callback. This should be used if you want event logging
* information from the client library.
*
* mosq - a valid mosquitto instance.
* on_log - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int level, const char *str)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* level - the log message level from the values:
* MOSQ_LOG_INFO
* MOSQ_LOG_NOTICE
* MOSQ_LOG_WARNING
* MOSQ_LOG_ERR
* MOSQ_LOG_DEBUG
* str - the message string.
*/
libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *));
/* =============================================================================
*
* Section: SOCKS5 proxy functions
*
* =============================================================================
*/
/*
* Function: mosquitto_socks5_set
*
* Configure the client to use a SOCKS5 proxy when connecting. Must be called
* before connecting. "None" and "username/password" authentication is
* supported.
*
* Parameters:
* mosq - a valid mosquitto instance.
* host - the SOCKS5 proxy host to connect to.
* port - the SOCKS5 proxy port to use.
* username - if not NULL, use this username when authenticating with the proxy.
* password - if not NULL and username is not NULL, use this password when
* authenticating with the proxy.
*/
libmosq_EXPORT int mosquitto_socks5_set(struct mosquitto *mosq, const char *host, int port, const char *username, const char *password);
/* =============================================================================
*
* Section: Utility functions
*
* =============================================================================
*/
/*
* Function: mosquitto_strerror
*
* Call to obtain a const string description of a mosquitto error number.
*
* Parameters:
* mosq_errno - a mosquitto error number.
*
* Returns:
* A constant string describing the error.
*/
libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno);
/*
* Function: mosquitto_connack_string
*
* Call to obtain a const string description of an MQTT connection result.
*
* Parameters:
* connack_code - an MQTT connection result.
*
* Returns:
* A constant string describing the result.
*/
libmosq_EXPORT const char *mosquitto_connack_string(int connack_code);
/*
* Function: mosquitto_reason_string
*
* Call to obtain a const string description of an MQTT reason code.
*
* Parameters:
* reason_code - an MQTT reason code.
*
* Returns:
* A constant string describing the reason.
*/
libmosq_EXPORT const char *mosquitto_reason_string(int reason_code);
/* Function: mosquitto_string_to_command
*
* Take a string input representing an MQTT command and convert it to the
* libmosquitto integer representation.
*
* Parameters:
* str - the string to parse.
* cmd - pointer to an int, for the result.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - on an invalid input.
*
* Example:
* (start code)
* mosquitto_string_to_command("CONNECT", &cmd);
* // cmd == CMD_CONNECT
* (end)
*/
libmosq_EXPORT int mosquitto_string_to_command(const char *str, int *cmd);
/*
* Function: mosquitto_sub_topic_tokenise
*
* Tokenise a topic or subscription string into an array of strings
* representing the topic hierarchy.
*
* For example:
*
* subtopic: "a/deep/topic/hierarchy"
*
* Would result in:
*
* topics[0] = "a"
* topics[1] = "deep"
* topics[2] = "topic"
* topics[3] = "hierarchy"
*
* and:
*
* subtopic: "/a/deep/topic/hierarchy/"
*
* Would result in:
*
* topics[0] = NULL
* topics[1] = "a"
* topics[2] = "deep"
* topics[3] = "topic"
* topics[4] = "hierarchy"
*
* Parameters:
* subtopic - the subscription/topic to tokenise
* topics - a pointer to store the array of strings
* count - an int pointer to store the number of items in the topics array.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
*
* Example:
*
* > char **topics;
* > int topic_count;
* > int i;
* >
* > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count);
* >
* > for(i=0; i<token_count; i++){
* > printf("%d: %s\n", i, topics[i]);
* > }
*
* See Also:
* <mosquitto_sub_topic_tokens_free>
*/
libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count);
/*
* Function: mosquitto_sub_topic_tokens_free
*
* Free memory that was allocated in <mosquitto_sub_topic_tokenise>.
*
* Parameters:
* topics - pointer to string array.
* count - count of items in string array.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if the input parameters were invalid.
*
* See Also:
* <mosquitto_sub_topic_tokenise>
*/
libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count);
/*
* Function: mosquitto_topic_matches_sub
*
* Check whether a topic matches a subscription.
*
* For example:
*
* foo/bar would match the subscription foo/# or +/bar
* non/matching would not match the subscription non/+/+
*
* Parameters:
* sub - subscription string to check topic against.
* topic - topic to check.
* result - bool pointer to hold result. Will be set to true if the topic
* matches the subscription.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*/
libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result);
/*
* Function: mosquitto_topic_matches_sub2
*
* Check whether a topic matches a subscription.
*
* For example:
*
* foo/bar would match the subscription foo/# or +/bar
* non/matching would not match the subscription non/+/+
*
* Parameters:
* sub - subscription string to check topic against.
* sublen - length in bytes of sub string
* topic - topic to check.
* topiclen - length in bytes of topic string
* result - bool pointer to hold result. Will be set to true if the topic
* matches the subscription.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
*/
libmosq_EXPORT int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *topic, size_t topiclen, bool *result);
/*
* Function: mosquitto_pub_topic_check
*
* Check whether a topic to be used for publishing is valid.
*
* This searches for + or # in a topic and checks its length.
*
* This check is already carried out in <mosquitto_publish> and
* <mosquitto_will_set>, there is no need to call it directly before them. It
* may be useful if you wish to check the validity of a topic in advance of
* making a connection for example.
*
* Parameters:
* topic - the topic to check
*
* Returns:
* MOSQ_ERR_SUCCESS - for a valid topic
* MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long.
* MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8
*
* See Also:
* <mosquitto_sub_topic_check>
*/
libmosq_EXPORT int mosquitto_pub_topic_check(const char *topic);
/*
* Function: mosquitto_pub_topic_check2
*
* Check whether a topic to be used for publishing is valid.
*
* This searches for + or # in a topic and checks its length.
*
* This check is already carried out in <mosquitto_publish> and
* <mosquitto_will_set>, there is no need to call it directly before them. It
* may be useful if you wish to check the validity of a topic in advance of
* making a connection for example.
*
* Parameters:
* topic - the topic to check
* topiclen - length of the topic in bytes
*
* Returns:
* MOSQ_ERR_SUCCESS - for a valid topic
* MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long.
* MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8
*
* See Also:
* <mosquitto_sub_topic_check>
*/
libmosq_EXPORT int mosquitto_pub_topic_check2(const char *topic, size_t topiclen);
/*
* Function: mosquitto_sub_topic_check
*
* Check whether a topic to be used for subscribing is valid.
*
* This searches for + or # in a topic and checks that they aren't in invalid
* positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its
* length.
*
* This check is already carried out in <mosquitto_subscribe> and
* <mosquitto_unsubscribe>, there is no need to call it directly before them.
* It may be useful if you wish to check the validity of a topic in advance of
* making a connection for example.
*
* Parameters:
* topic - the topic to check
*
* Returns:
* MOSQ_ERR_SUCCESS - for a valid topic
* MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an
* invalid position, or if it is too long.
* MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8
*
* See Also:
* <mosquitto_sub_topic_check>
*/
libmosq_EXPORT int mosquitto_sub_topic_check(const char *topic);
/*
* Function: mosquitto_sub_topic_check2
*
* Check whether a topic to be used for subscribing is valid.
*
* This searches for + or # in a topic and checks that they aren't in invalid
* positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its
* length.
*
* This check is already carried out in <mosquitto_subscribe> and
* <mosquitto_unsubscribe>, there is no need to call it directly before them.
* It may be useful if you wish to check the validity of a topic in advance of
* making a connection for example.
*
* Parameters:
* topic - the topic to check
* topiclen - the length in bytes of the topic
*
* Returns:
* MOSQ_ERR_SUCCESS - for a valid topic
* MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an
* invalid position, or if it is too long.
* MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8
*
* See Also:
* <mosquitto_sub_topic_check>
*/
libmosq_EXPORT int mosquitto_sub_topic_check2(const char *topic, size_t topiclen);
/*
* Function: mosquitto_validate_utf8
*
* Helper function to validate whether a UTF-8 string is valid, according to
* the UTF-8 spec and the MQTT additions.
*
* Parameters:
* str - a string to check
* len - the length of the string in bytes
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if str is NULL or len<0 or len>65536
* MOSQ_ERR_MALFORMED_UTF8 - if str is not valid UTF-8
*/
libmosq_EXPORT int mosquitto_validate_utf8(const char *str, int len);
/* =============================================================================
*
* Section: One line client helper functions
*
* =============================================================================
*/
struct libmosquitto_will {
char *topic;
void *payload;
int payloadlen;
int qos;
bool retain;
};
struct libmosquitto_auth {
char *username;
char *password;
};
struct libmosquitto_tls {
char *cafile;
char *capath;
char *certfile;
char *keyfile;
char *ciphers;
char *tls_version;
int (*pw_callback)(char *buf, int size, int rwflag, void *userdata);
int cert_reqs;
};
/*
* Function: mosquitto_subscribe_simple
*
* Helper function to make subscribing to a topic and retrieving some messages
* very straightforward.
*
* This connects to a broker, subscribes to a topic, waits for msg_count
* messages to be received, then returns after disconnecting cleanly.
*
* Parameters:
* messages - pointer to a "struct mosquitto_message *". The received
* messages will be returned here. On error, this will be set to
* NULL.
* msg_count - the number of messages to retrieve.
* want_retained - if set to true, stale retained messages will be treated as
* normal messages with regards to msg_count. If set to
* false, they will be ignored.
* topic - the subscription topic to use (wildcards are allowed).
* qos - the qos to use for the subscription.
* host - the broker to connect to.
* port - the network port the broker is listening on.
* client_id - the client id to use, or NULL if a random client id should be
* generated.
* keepalive - the MQTT keepalive value.
* clean_session - the MQTT clean session flag.
* username - the username string, or NULL for no username authentication.
* password - the password string, or NULL for an empty password.
* will - a libmosquitto_will struct containing will information, or NULL for
* no will.
* tls - a libmosquitto_tls struct containing TLS related parameters, or NULL
* for no use of TLS.
*
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* Greater than 0 - on error.
*/
libmosq_EXPORT int mosquitto_subscribe_simple(
struct mosquitto_message **messages,
int msg_count,
bool want_retained,
const char *topic,
int qos,
const char *host,
int port,
const char *client_id,
int keepalive,
bool clean_session,
const char *username,
const char *password,
const struct libmosquitto_will *will,
const struct libmosquitto_tls *tls);
/*
* Function: mosquitto_subscribe_callback
*
* Helper function to make subscribing to a topic and processing some messages
* very straightforward.
*
* This connects to a broker, subscribes to a topic, then passes received
* messages to a user provided callback. If the callback returns a 1, it then
* disconnects cleanly and returns.
*
* Parameters:
* callback - a callback function in the following form:
* int callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
* Note that this is the same as the normal on_message callback,
* except that it returns an int.
* userdata - user provided pointer that will be passed to the callback.
* topic - the subscription topic to use (wildcards are allowed).
* qos - the qos to use for the subscription.
* host - the broker to connect to.
* port - the network port the broker is listening on.
* client_id - the client id to use, or NULL if a random client id should be
* generated.
* keepalive - the MQTT keepalive value.
* clean_session - the MQTT clean session flag.
* username - the username string, or NULL for no username authentication.
* password - the password string, or NULL for an empty password.
* will - a libmosquitto_will struct containing will information, or NULL for
* no will.
* tls - a libmosquitto_tls struct containing TLS related parameters, or NULL
* for no use of TLS.
*
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* Greater than 0 - on error.
*/
libmosq_EXPORT int mosquitto_subscribe_callback(
int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *),
void *userdata,
const char *topic,
int qos,
const char *host,
int port,
const char *client_id,
int keepalive,
bool clean_session,
const char *username,
const char *password,
const struct libmosquitto_will *will,
const struct libmosquitto_tls *tls);
/* =============================================================================
*
* Section: Properties
*
* =============================================================================
*/
/*
* Function: mosquitto_property_add_byte
*
* Add a new byte property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - integer value for the new property
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_byte(&proplist, MQTT_PROP_PAYLOAD_FORMAT_IDENTIFIER, 1);
*/
libmosq_EXPORT int mosquitto_property_add_byte(mosquitto_property **proplist, int identifier, uint8_t value);
/*
* Function: mosquitto_property_add_int16
*
* Add a new int16 property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_RECEIVE_MAXIMUM)
* value - integer value for the new property
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_int16(&proplist, MQTT_PROP_RECEIVE_MAXIMUM, 1000);
*/
libmosq_EXPORT int mosquitto_property_add_int16(mosquitto_property **proplist, int identifier, uint16_t value);
/*
* Function: mosquitto_property_add_int32
*
* Add a new int32 property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_MESSAGE_EXPIRY_INTERVAL)
* value - integer value for the new property
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_int32(&proplist, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 86400);
*/
libmosq_EXPORT int mosquitto_property_add_int32(mosquitto_property **proplist, int identifier, uint32_t value);
/*
* Function: mosquitto_property_add_varint
*
* Add a new varint property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_SUBSCRIPTION_IDENTIFIER)
* value - integer value for the new property
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_varint(&proplist, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 1);
*/
libmosq_EXPORT int mosquitto_property_add_varint(mosquitto_property **proplist, int identifier, uint32_t value);
/*
* Function: mosquitto_property_add_binary
*
* Add a new binary property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to the property data
* len - length of property data in bytes
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_binary(&proplist, MQTT_PROP_AUTHENTICATION_DATA, auth_data, auth_data_len);
*/
libmosq_EXPORT int mosquitto_property_add_binary(mosquitto_property **proplist, int identifier, const void *value, uint16_t len);
/*
* Function: mosquitto_property_add_string
*
* Add a new string property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_CONTENT_TYPE)
* value - string value for the new property, must be UTF-8 and zero terminated
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, if value is NULL, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
* MOSQ_ERR_MALFORMED_UTF8 - value is not valid UTF-8.
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_string(&proplist, MQTT_PROP_CONTENT_TYPE, "application/json");
*/
libmosq_EXPORT int mosquitto_property_add_string(mosquitto_property **proplist, int identifier, const char *value);
/*
* Function: mosquitto_property_add_string_pair
*
* Add a new string pair property to a property list.
*
* If *proplist == NULL, a new list will be created, otherwise the new property
* will be appended to the list.
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_USER_PROPERTY)
* name - string name for the new property, must be UTF-8 and zero terminated
* value - string value for the new property, must be UTF-8 and zero terminated
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if identifier is invalid, if name or value is NULL, or if proplist is NULL
* MOSQ_ERR_NOMEM - on out of memory
* MOSQ_ERR_MALFORMED_UTF8 - if name or value are not valid UTF-8.
*
* Example:
* > mosquitto_property *proplist = NULL;
* > mosquitto_property_add_string_pair(&proplist, MQTT_PROP_USER_PROPERTY, "client", "mosquitto_pub");
*/
libmosq_EXPORT int mosquitto_property_add_string_pair(mosquitto_property **proplist, int identifier, const char *name, const char *value);
/*
* Function: mosquitto_property_identifier
*
* Return the property identifier for a single property.
*
* Parameters:
* property - pointer to a valid mosquitto_property pointer.
*
* Returns:
* A valid property identifier on success
* 0 - on error
*/
libmosq_EXPORT int mosquitto_property_identifier(const mosquitto_property *property);
/*
* Function: mosquitto_property_next
*
* Return the next property in a property list. Use to iterate over a property
* list, e.g.:
*
* (start code)
* for(prop = proplist; prop != NULL; prop = mosquitto_property_next(prop)){
* if(mosquitto_property_identifier(prop) == MQTT_PROP_CONTENT_TYPE){
* ...
* }
* }
* (end)
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
*
* Returns:
* Pointer to the next item in the list
* NULL, if proplist is NULL, or if there are no more items in the list.
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_next(const mosquitto_property *proplist);
/*
* Function: mosquitto_property_read_byte
*
* Attempt to read a byte property matching an identifier, from a property list
* or single property. This function can search for multiple entries of the
* same identifier by using the returned value and skip_first. Note however
* that it is forbidden for most properties to be duplicated.
*
* If the property is not found, *value will not be modified, so it is safe to
* pass a variable with a default value to be potentially overwritten:
*
* (start code)
* uint16_t keepalive = 60; // default value
* // Get value from property list, or keep default if not found.
* mosquitto_property_read_int16(proplist, MQTT_PROP_SERVER_KEEP_ALIVE, &keepalive, false);
* (end)
*
* Parameters:
* proplist - mosquitto_property pointer, the list of properties or single property
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to store the value, or NULL if the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL.
*
* Example:
* (start code)
* // proplist is obtained from a callback
* mosquitto_property *prop;
* prop = mosquitto_property_read_byte(proplist, identifier, &value, false);
* while(prop){
* printf("value: %s\n", value);
* prop = mosquitto_property_read_byte(prop, identifier, &value);
* }
* (end)
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_byte(
const mosquitto_property *proplist,
int identifier,
uint8_t *value,
bool skip_first);
/*
* Function: mosquitto_property_read_int16
*
* Read an int16 property value from a property.
*
* Parameters:
* property - property to read
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to store the value, or NULL if the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL.
*
* Example:
* See <mosquitto_property_read_byte>
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int16(
const mosquitto_property *proplist,
int identifier,
uint16_t *value,
bool skip_first);
/*
* Function: mosquitto_property_read_int32
*
* Read an int32 property value from a property.
*
* Parameters:
* property - pointer to mosquitto_property pointer, the list of properties
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to store the value, or NULL if the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL.
*
* Example:
* See <mosquitto_property_read_byte>
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int32(
const mosquitto_property *proplist,
int identifier,
uint32_t *value,
bool skip_first);
/*
* Function: mosquitto_property_read_varint
*
* Read a varint property value from a property.
*
* Parameters:
* property - property to read
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to store the value, or NULL if the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL.
*
* Example:
* See <mosquitto_property_read_byte>
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_varint(
const mosquitto_property *proplist,
int identifier,
uint32_t *value,
bool skip_first);
/*
* Function: mosquitto_property_read_binary
*
* Read a binary property value from a property.
*
* On success, value must be free()'d by the application.
*
* Parameters:
* property - property to read
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to store the value, or NULL if the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred.
*
* Example:
* See <mosquitto_property_read_byte>
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_binary(
const mosquitto_property *proplist,
int identifier,
void **value,
uint16_t *len,
bool skip_first);
/*
* Function: mosquitto_property_read_string
*
* Read a string property value from a property.
*
* On success, value must be free()'d by the application.
*
* Parameters:
* property - property to read
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* value - pointer to char*, for the property data to be stored in, or NULL if
* the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred.
*
* Example:
* See <mosquitto_property_read_byte>
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string(
const mosquitto_property *proplist,
int identifier,
char **value,
bool skip_first);
/*
* Function: mosquitto_property_read_string_pair
*
* Read a string pair property value pair from a property.
*
* On success, name and value must be free()'d by the application.
*
* Parameters:
* property - property to read
* identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
* name - pointer to char* for the name property data to be stored in, or NULL
* if the name is not required.
* value - pointer to char*, for the property data to be stored in, or NULL if
* the value is not required.
* skip_first - boolean that indicates whether the first item in the list
* should be ignored or not. Should usually be set to false.
*
* Returns:
* A valid property pointer if the property is found
* NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred.
*
* Example:
* See <mosquitto_property_read_byte>
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string_pair(
const mosquitto_property *proplist,
int identifier,
char **name,
char **value,
bool skip_first);
/*
* Function: mosquitto_property_free_all
*
* Free all properties from a list of properties. Frees the list and sets *properties to NULL.
*
* Parameters:
* properties - list of properties to free
*
* Example:
* > mosquitto_properties *properties = NULL;
* > // Add properties
* > mosquitto_property_free_all(&properties);
*/
libmosq_EXPORT void mosquitto_property_free_all(mosquitto_property **properties);
/*
* Function: mosquitto_property_copy_all
*
* Parameters:
* dest - pointer for new property list
* src - property list
*
* Returns:
* MOSQ_ERR_SUCCESS - on successful copy
* MOSQ_ERR_INVAL - if dest is NULL
* MOSQ_ERR_NOMEM - on out of memory (dest will be set to NULL)
*/
libmosq_EXPORT int mosquitto_property_copy_all(mosquitto_property **dest, const mosquitto_property *src);
/*
* Function: mosquitto_property_check_command
*
* Check whether a property identifier is valid for the given command.
*
* Parameters:
* command - MQTT command (e.g. CMD_CONNECT)
* identifier - MQTT property (e.g. MQTT_PROP_USER_PROPERTY)
*
* Returns:
* MOSQ_ERR_SUCCESS - if the identifier is valid for command
* MOSQ_ERR_PROTOCOL - if the identifier is not valid for use with command.
*/
libmosq_EXPORT int mosquitto_property_check_command(int command, int identifier);
/*
* Function: mosquitto_property_check_all
*
* Check whether a list of properties are valid for a particular command,
* whether there are duplicates, and whether the values are valid where
* possible.
*
* Note that this function is used internally in the library whenever
* properties are passed to it, so in basic use this is not needed, but should
* be helpful to check property lists *before* the point of using them.
*
* Parameters:
* command - MQTT command (e.g. CMD_CONNECT)
* properties - list of MQTT properties to check.
*
* Returns:
* MOSQ_ERR_SUCCESS - if all properties are valid
* MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
* MOSQ_ERR_PROTOCOL - if any property is invalid
*/
libmosq_EXPORT int mosquitto_property_check_all(int command, const mosquitto_property *properties);
/*
* Function: mosquitto_property_identifier_to_string
*
* Return the property name as a string for a property identifier.
* The property name is as defined in the MQTT specification, with - as a
* separator, for example: payload-format-indicator.
*
* Parameters:
* identifier - valid MQTT property identifier integer
*
* Returns:
* A const string to the property name on success
* NULL on failure
*/
libmosq_EXPORT const char *mosquitto_property_identifier_to_string(int identifier);
/* Function: mosquitto_string_to_property_info
*
* Parse a property name string and convert to a property identifier and data type.
* The property name is as defined in the MQTT specification, with - as a
* separator, for example: payload-format-indicator.
*
* Parameters:
* propname - the string to parse
* identifier - pointer to an int to receive the property identifier
* type - pointer to an int to receive the property type
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if the string does not match a property
*
* Example:
* (start code)
* mosquitto_string_to_property_info("response-topic", &id, &type);
* // id == MQTT_PROP_RESPONSE_TOPIC
* // type == MQTT_PROP_TYPE_STRING
* (end)
*/
libmosq_EXPORT int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type);
#ifdef __cplusplus
}
#endif
#endif
|