├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── moe │ │ │ └── key │ │ │ └── yao │ │ │ └── mqtt │ │ │ └── client │ │ │ └── MainActivity.kt │ ├── test │ │ └── java │ │ │ └── moe │ │ │ └── key │ │ │ └── yao │ │ │ └── mqtt │ │ │ └── client │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── moe │ │ └── key │ │ └── yao │ │ └── mqtt │ │ └── client │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── library ├── consumer-rules.pro ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── jni │ │ │ ├── lib │ │ │ │ ├── x86 │ │ │ │ │ ├── libssl.a │ │ │ │ │ └── libcrypto.a │ │ │ │ ├── arm64-v8a │ │ │ │ │ ├── libssl.a │ │ │ │ │ └── libcrypto.a │ │ │ │ └── armeabi-v7a │ │ │ │ │ ├── libssl.a │ │ │ │ │ └── libcrypto.a │ │ │ ├── Application.mk │ │ │ ├── MqttClient.h │ │ │ ├── mosquitto │ │ │ │ ├── lib │ │ │ │ │ ├── dummypthread.h │ │ │ │ │ ├── time_mosq.h │ │ │ │ │ ├── socks_mosq.h │ │ │ │ │ ├── logging_mosq.h │ │ │ │ │ ├── alias_mosq.h │ │ │ │ │ ├── will_mosq.h │ │ │ │ │ ├── tls_mosq.h │ │ │ │ │ ├── memory_mosq.h │ │ │ │ │ ├── handle_auth.c │ │ │ │ │ ├── read_handle.h │ │ │ │ │ ├── messages_mosq.h │ │ │ │ │ ├── property_mosq.h │ │ │ │ │ ├── time_mosq.c │ │ │ │ │ ├── logging_mosq.c │ │ │ │ │ ├── handle_disconnect.c │ │ │ │ │ ├── util_mosq.h │ │ │ │ │ ├── handle_ping.c │ │ │ │ │ ├── read_handle.c │ │ │ │ │ ├── send_mosq.h │ │ │ │ │ ├── alias_mosq.c │ │ │ │ │ ├── packet_mosq.h │ │ │ │ │ ├── send_disconnect.c │ │ │ │ │ ├── handle_unsuback.c │ │ │ │ │ ├── send_subscribe.c │ │ │ │ │ ├── net_mosq.h │ │ │ │ │ ├── send_unsubscribe.c │ │ │ │ │ ├── handle_suback.c │ │ │ │ │ ├── srv_mosq.c │ │ │ │ │ ├── thread_mosq.c │ │ │ │ │ ├── utf8_mosq.c │ │ │ │ │ ├── handle_pubrec.c │ │ │ │ │ ├── memory_mosq.c │ │ │ │ │ ├── will_mosq.c │ │ │ │ │ ├── handle_pubackcomp.c │ │ │ │ │ ├── handle_pubrel.c │ │ │ │ │ ├── handle_connack.c │ │ │ │ │ └── callbacks.c │ │ │ │ └── config.h │ │ │ ├── openssl │ │ │ │ └── include │ │ │ │ │ └── openssl │ │ │ │ │ ├── ebcdic.h │ │ │ │ │ ├── whrlpool.h │ │ │ │ │ ├── comp.h │ │ │ │ │ ├── pem2.h │ │ │ │ │ ├── cmac.h │ │ │ │ │ ├── ui_compat.h │ │ │ │ │ ├── ssl23.h │ │ │ │ │ ├── rc4.h │ │ │ │ │ ├── pqueue.h │ │ │ │ │ ├── mdc2.h │ │ │ │ │ ├── opensslv.h │ │ │ │ │ ├── conf_api.h │ │ │ │ │ ├── ripemd.h │ │ │ │ │ ├── rc2.h │ │ │ │ │ ├── stack.h │ │ │ │ │ ├── hmac.h │ │ │ │ │ ├── cast.h │ │ │ │ │ ├── txt_db.h │ │ │ │ │ ├── idea.h │ │ │ │ │ └── md4.h │ │ │ ├── JNIEnvHandler.h │ │ │ ├── mosquitto_wrapper.h │ │ │ ├── JNIEnvHandler.cpp │ │ │ ├── uthash │ │ │ │ └── src │ │ │ │ │ └── utstack.h │ │ │ └── Android.mk │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── moe │ │ │ └── key │ │ │ └── yao │ │ │ └── mqtt │ │ │ └── library │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── moe │ │ └── key │ │ └── yao │ │ └── mqtt │ │ └── library │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── gradlew.bat └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | rootProject.name='mqtt_client_android' 3 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | library 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | mqtt_client_android 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/jni/lib/x86/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/library/src/main/jni/lib/x86/libssl.a -------------------------------------------------------------------------------- /library/src/main/jni/lib/x86/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/library/src/main/jni/lib/x86/libcrypto.a -------------------------------------------------------------------------------- /library/src/main/jni/lib/arm64-v8a/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/library/src/main/jni/lib/arm64-v8a/libssl.a -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/jni/lib/armeabi-v7a/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/library/src/main/jni/lib/armeabi-v7a/libssl.a -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /library/src/main/jni/lib/arm64-v8a/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/library/src/main/jni/lib/arm64-v8a/libcrypto.a -------------------------------------------------------------------------------- /library/src/main/jni/lib/armeabi-v7a/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/library/src/main/jni/lib/armeabi-v7a/libcrypto.a -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeyYao/mqtt_client_android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /library/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_OPTIM := release 2 | APP_ABI := armeabi-v7a x86 arm64-v8a 3 | APP_STL := c++_static 4 | APP_PLATFORM := android-21 5 | APP_PIE := false -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Feb 20 16:48:15 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /library/src/main/jni/MqttClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Key.Yao on 2020-02-20. 3 | // 4 | 5 | #ifndef MQTT_CLIENT_ANDROID_MQTTCLIENT_H 6 | #define MQTT_CLIENT_ANDROID_MQTTCLIENT_H 7 | 8 | 9 | class MqttClient { 10 | 11 | }; 12 | 13 | 14 | #endif //MQTT_CLIENT_ANDROID_MQTTCLIENT_H 15 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/dummypthread.h: -------------------------------------------------------------------------------- 1 | #ifndef DUMMYPTHREAD_H 2 | #define DUMMYPTHREAD_H 3 | 4 | #define pthread_create(A, B, C, D) 5 | #define pthread_join(A, B) 6 | #define pthread_cancel(A) 7 | 8 | #define pthread_mutex_init(A, B) 9 | #define pthread_mutex_destroy(A) 10 | #define pthread_mutex_lock(A) 11 | #define pthread_mutex_unlock(A) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/moe/key/yao/mqtt/client/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package moe.key.yao.mqtt.client 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /library/src/test/java/moe/key/yao/mqtt/library/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package moe.key.yao.mqtt.library; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/time_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef TIME_MOSQ_H 18 | #define TIME_MOSQ_H 19 | 20 | time_t mosquitto_time(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /library/src/main/jni/openssl/include/openssl/ebcdic.h: -------------------------------------------------------------------------------- 1 | /* crypto/ebcdic.h */ 2 | 3 | #ifndef HEADER_EBCDIC_H 4 | # define HEADER_EBCDIC_H 5 | 6 | # include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Avoid name clashes with other applications */ 13 | # define os_toascii _openssl_os_toascii 14 | # define os_toebcdic _openssl_os_toebcdic 15 | # define ebcdic2ascii _openssl_ebcdic2ascii 16 | # define ascii2ebcdic _openssl_ascii2ebcdic 17 | 18 | extern const unsigned char os_toascii[256]; 19 | extern const unsigned char os_toebcdic[256]; 20 | void *ebcdic2ascii(void *dest, const void *srce, size_t count); 21 | void *ascii2ebcdic(void *dest, const void *srce, size_t count); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/socks_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef SOCKS_MOSQ_H 18 | #define SOCKS_MOSQ_H 19 | 20 | int socks5__send(struct mosquitto *mosq); 21 | int socks5__read(struct mosquitto *mosq); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/logging_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef LOGGING_MOSQ_H 17 | #define LOGGING_MOSQ_H 18 | 19 | #include "mosquitto.h" 20 | 21 | int log__printf(struct mosquitto *mosq, int priority, const char *fmt, ...); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/moe/key/yao/mqtt/client/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package moe.key.yao.mqtt.client 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("moe.key.yao.mqtt.client", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/alias_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef ALIAS_MOSQ_H 18 | #define ALIAS_MOSQ_H 19 | 20 | #include "mosquitto_internal.h" 21 | 22 | int alias__add(struct mosquitto *mosq, const char *topic, int alias); 23 | int alias__find(struct mosquitto *mosq, char **topic, int alias); 24 | void alias__free_all(struct mosquitto *mosq); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /library/src/androidTest/java/moe/key/yao/mqtt/library/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package moe.key.yao.mqtt.library; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("moe.key.yao.mqtt.library.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/will_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef WILL_MOSQ_H 18 | #define WILL_MOSQ_H 19 | 20 | #include "mosquitto.h" 21 | #include "mosquitto_internal.h" 22 | 23 | int will__set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties); 24 | int will__clear(struct mosquitto *mosq); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/tls_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef TLS_MOSQ_H 18 | #define TLS_MOSQ_H 19 | 20 | #ifdef WITH_TLS 21 | # define SSL_DATA_PENDING(A) ((A)->ssl && SSL_pending((A)->ssl)) 22 | #else 23 | # define SSL_DATA_PENDING(A) 0 24 | #endif 25 | 26 | #ifdef WITH_TLS 27 | 28 | #include 29 | #include 30 | 31 | int mosquitto__server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx); 32 | int mosquitto__verify_certificate_hostname(X509 *cert, const char *hostname); 33 | 34 | #endif /* WITH_TLS */ 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /library/src/main/jni/JNIEnvHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Key.Yao on 2020-02-20. 3 | // 4 | 5 | #ifndef MQTT_CLIENT_ANDROID_JNIENVHANDLER_H 6 | #define MQTT_CLIENT_ANDROID_JNIENVHANDLER_H 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | typedef void(*handleMessage)(int what, void* obj, JNIEnv *env, jobject instance); 16 | 17 | struct ThreadMessage; 18 | 19 | class JNIEnvHandler { 20 | 21 | public: 22 | JNIEnvHandler(const char* threadName); 23 | 24 | ~JNIEnvHandler(); 25 | 26 | bool init(JavaVM *vm, jobject instance, handleMessage callback); 27 | 28 | void exit(); 29 | 30 | std::thread::id getThreadId(); 31 | 32 | void post(int what, void *obj = nullptr); 33 | 34 | 35 | private: 36 | JNIEnvHandler(const JNIEnvHandler&); 37 | JNIEnvHandler&operator=(const JNIEnvHandler&); 38 | 39 | void process(); 40 | 41 | JavaVM *_vm; 42 | jobject _instance; 43 | std::thread *_thread; 44 | std::queue _queue; 45 | std::mutex _mutex; 46 | std::condition_variable _cv; 47 | std::atomic _exitFlag; 48 | handleMessage _callback; 49 | const char* _threadName; 50 | 51 | }; 52 | 53 | 54 | #endif //MQTT_CLIENT_ANDROID_JNIENVHANDLER_H 55 | -------------------------------------------------------------------------------- /library/src/main/jni/openssl/include/openssl/whrlpool.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_WHRLPOOL_H 2 | # define HEADER_WHRLPOOL_H 3 | 4 | # include 5 | # include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | # define WHIRLPOOL_DIGEST_LENGTH (512/8) 12 | # define WHIRLPOOL_BBLOCK 512 13 | # define WHIRLPOOL_COUNTER (256/8) 14 | 15 | typedef struct { 16 | union { 17 | unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; 18 | /* double q is here to ensure 64-bit alignment */ 19 | double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)]; 20 | } H; 21 | unsigned char data[WHIRLPOOL_BBLOCK / 8]; 22 | unsigned int bitoff; 23 | size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)]; 24 | } WHIRLPOOL_CTX; 25 | 26 | # ifndef OPENSSL_NO_WHIRLPOOL 27 | # ifdef OPENSSL_FIPS 28 | int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 29 | # endif 30 | int WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 31 | int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes); 32 | void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits); 33 | int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c); 34 | unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md); 35 | # endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/memory_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #ifndef MEMORY_MOSQ_H 18 | #define MEMORY_MOSQ_H 19 | 20 | #include 21 | #include 22 | 23 | #if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) && defined(__GLIBC__) 24 | #define REAL_WITH_MEMORY_TRACKING 25 | #endif 26 | 27 | void *mosquitto__calloc(size_t nmemb, size_t size); 28 | void mosquitto__free(void *mem); 29 | void *mosquitto__malloc(size_t size); 30 | #ifdef REAL_WITH_MEMORY_TRACKING 31 | unsigned long mosquitto__memory_used(void); 32 | unsigned long mosquitto__max_memory_used(void); 33 | #endif 34 | void *mosquitto__realloc(void *ptr, size_t size); 35 | char *mosquitto__strdup(const char *s); 36 | 37 | #ifdef WITH_BROKER 38 | void memory__set_limit(size_t lim); 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/handle_auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | 22 | #include "logging_mosq.h" 23 | #include "mosquitto_internal.h" 24 | #include "mqtt_protocol.h" 25 | #include "packet_mosq.h" 26 | #include "property_mosq.h" 27 | 28 | 29 | int handle__auth(struct mosquitto *mosq) 30 | { 31 | int rc = 0; 32 | uint8_t reason_code; 33 | mosquitto_property *properties = NULL; 34 | 35 | if(!mosq) return MOSQ_ERR_INVAL; 36 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received AUTH", mosq->id); 37 | 38 | if(mosq->protocol != mosq_p_mqtt5){ 39 | return MOSQ_ERR_PROTOCOL; 40 | } 41 | 42 | if(packet__read_byte(&mosq->in_packet, &reason_code)) return 1; 43 | 44 | rc = property__read_all(CMD_AUTH, &mosq->in_packet, &properties); 45 | if(rc) return rc; 46 | mosquitto_property_free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */ 47 | 48 | return MOSQ_ERR_SUCCESS; 49 | } 50 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/read_handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef READ_HANDLE_H 17 | #define READ_HANDLE_H 18 | 19 | #include "mosquitto.h" 20 | struct mosquitto_db; 21 | 22 | int handle__pingreq(struct mosquitto *mosq); 23 | int handle__pingresp(struct mosquitto *mosq); 24 | #ifdef WITH_BROKER 25 | int handle__pubackcomp(struct mosquitto_db *db, struct mosquitto *mosq, const char *type); 26 | #else 27 | int handle__packet(struct mosquitto *mosq); 28 | int handle__connack(struct mosquitto *mosq); 29 | int handle__disconnect(struct mosquitto *mosq); 30 | int handle__pubackcomp(struct mosquitto *mosq, const char *type); 31 | int handle__publish(struct mosquitto *mosq); 32 | int handle__auth(struct mosquitto *mosq); 33 | #endif 34 | int handle__pubrec(struct mosquitto_db *db, struct mosquitto *mosq); 35 | int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq); 36 | int handle__suback(struct mosquitto *mosq); 37 | int handle__unsuback(struct mosquitto *mosq); 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/messages_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef MESSAGES_MOSQ_H 17 | #define MESSAGES_MOSQ_H 18 | 19 | #include "mosquitto_internal.h" 20 | #include "mosquitto.h" 21 | 22 | void message__cleanup_all(struct mosquitto *mosq); 23 | void message__cleanup(struct mosquitto_message_all **message); 24 | int message__delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, int qos); 25 | int message__queue(struct mosquitto *mosq, struct mosquitto_message_all *message, enum mosquitto_msg_direction dir); 26 | void message__reconnect_reset(struct mosquitto *mosq); 27 | int message__release_to_inflight(struct mosquitto *mosq, enum mosquitto_msg_direction dir); 28 | int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message, int qos); 29 | void message__retry_check(struct mosquitto *mosq); 30 | int message__out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_state state, int qos); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 21 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | consumerProguardFiles 'consumer-rules.pro' 16 | 17 | ndk { 18 | abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a' 19 | } 20 | 21 | externalNativeBuild { 22 | ndkBuild { 23 | arguments "NDK_APPLICATION_MK:=src/main/jni/Application.mk" 24 | abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a' 25 | } 26 | } 27 | } 28 | compileOptions { 29 | sourceCompatibility 1.8 30 | targetCompatibility 1.8 31 | } 32 | buildTypes { 33 | release { 34 | minifyEnabled false 35 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 36 | } 37 | } 38 | externalNativeBuild { 39 | ndkBuild { 40 | path file('src/main/jni/Android.mk') 41 | } 42 | } 43 | 44 | } 45 | 46 | dependencies { 47 | implementation fileTree(dir: 'libs', include: ['*.jar']) 48 | 49 | implementation 'androidx.appcompat:appcompat:1.1.0' 50 | testImplementation 'junit:junit:4.12' 51 | androidTestImplementation 'androidx.test.ext:junit:1.1.0' 52 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 53 | } 54 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/property_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef PROPERTY_MOSQ_H 17 | #define PROPERTY_MOSQ_H 18 | 19 | #include "mosquitto_internal.h" 20 | #include "mosquitto.h" 21 | 22 | struct mqtt__string { 23 | char *v; 24 | int len; 25 | }; 26 | 27 | struct mqtt5__property { 28 | struct mqtt5__property *next; 29 | union { 30 | uint8_t i8; 31 | uint16_t i16; 32 | uint32_t i32; 33 | uint32_t varint; 34 | struct mqtt__string bin; 35 | struct mqtt__string s; 36 | } value; 37 | struct mqtt__string name; 38 | int32_t identifier; 39 | bool client_generated; 40 | }; 41 | 42 | 43 | int property__read_all(int command, struct mosquitto__packet *packet, mosquitto_property **property); 44 | int property__write_all(struct mosquitto__packet *packet, const mosquitto_property *property, bool write_len); 45 | void property__free(mosquitto_property **property); 46 | 47 | int property__get_length(const mosquitto_property *property); 48 | int property__get_length_all(const mosquitto_property *property); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/time_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #ifdef __APPLE__ 20 | #include 21 | #include 22 | #endif 23 | 24 | #ifdef WIN32 25 | # define _WIN32_WINNT _WIN32_WINNT_VISTA 26 | # include 27 | #else 28 | # include 29 | #endif 30 | #include 31 | 32 | #include "mosquitto.h" 33 | #include "time_mosq.h" 34 | 35 | time_t mosquitto_time(void) 36 | { 37 | #ifdef WIN32 38 | return GetTickCount64()/1000; 39 | #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) 40 | struct timespec tp; 41 | 42 | clock_gettime(CLOCK_MONOTONIC, &tp); 43 | return tp.tv_sec; 44 | #elif defined(__APPLE__) 45 | static mach_timebase_info_data_t tb; 46 | uint64_t ticks; 47 | uint64_t sec; 48 | 49 | ticks = mach_absolute_time(); 50 | 51 | if(tb.denom == 0){ 52 | mach_timebase_info(&tb); 53 | } 54 | sec = ticks*tb.numer/tb.denom/1000000000; 55 | 56 | return (time_t)sec; 57 | #else 58 | return time(NULL); 59 | #endif 60 | } 61 | 62 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 29 9 | buildToolsVersion "29.0.2" 10 | defaultConfig { 11 | applicationId "moe.key.yao.mqtt.client" 12 | minSdkVersion 21 13 | targetSdkVersion 29 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | ndk { 18 | abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a' 19 | } 20 | } 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility 1.8 29 | targetCompatibility 1.8 30 | } 31 | kotlinOptions { 32 | jvmTarget = "1.8" 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation fileTree(dir: 'libs', include: ['*.jar']) 38 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 39 | implementation 'androidx.appcompat:appcompat:1.1.0' 40 | implementation 'androidx.core:core-ktx:1.2.0' 41 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 42 | implementation 'com.google.guava:guava:28.0-android' 43 | 44 | implementation project(':library') 45 | 46 | testImplementation 'junit:junit:4.12' 47 | androidTestImplementation 'androidx.test.ext:junit:1.1.0' 48 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 49 | } 50 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/logging_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "mosquitto_internal.h" 25 | #include "mosquitto.h" 26 | #include "memory_mosq.h" 27 | 28 | int log__printf(struct mosquitto *mosq, int priority, const char *fmt, ...) 29 | { 30 | va_list va; 31 | char *s; 32 | int len; 33 | 34 | assert(mosq); 35 | assert(fmt); 36 | 37 | pthread_mutex_lock(&mosq->log_callback_mutex); 38 | if(mosq->on_log){ 39 | len = strlen(fmt) + 500; 40 | s = mosquitto__malloc(len*sizeof(char)); 41 | if(!s){ 42 | pthread_mutex_unlock(&mosq->log_callback_mutex); 43 | return MOSQ_ERR_NOMEM; 44 | } 45 | 46 | va_start(va, fmt); 47 | vsnprintf(s, len, fmt, va); 48 | va_end(va); 49 | s[len-1] = '\0'; /* Ensure string is null terminated. */ 50 | 51 | mosq->on_log(mosq, mosq->userdata, priority, s); 52 | 53 | mosquitto__free(s); 54 | } 55 | pthread_mutex_unlock(&mosq->log_callback_mutex); 56 | 57 | return MOSQ_ERR_SUCCESS; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/handle_disconnect.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2018 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | 22 | #include "logging_mosq.h" 23 | #include "mqtt_protocol.h" 24 | #include "memory_mosq.h" 25 | #include "net_mosq.h" 26 | #include "packet_mosq.h" 27 | #include "property_mosq.h" 28 | #include "send_mosq.h" 29 | #include "util_mosq.h" 30 | 31 | int handle__disconnect(struct mosquitto *mosq) 32 | { 33 | int rc; 34 | uint8_t reason_code; 35 | mosquitto_property *properties = NULL; 36 | 37 | if(!mosq){ 38 | return MOSQ_ERR_INVAL; 39 | } 40 | 41 | if(mosq->protocol != mosq_p_mqtt5){ 42 | return MOSQ_ERR_PROTOCOL; 43 | } 44 | 45 | rc = packet__read_byte(&mosq->in_packet, &reason_code); 46 | if(rc) return rc; 47 | 48 | if(mosq->in_packet.remaining_length > 2){ 49 | rc = property__read_all(CMD_DISCONNECT, &mosq->in_packet, &properties); 50 | if(rc) return rc; 51 | mosquitto_property_free_all(&properties); 52 | } 53 | 54 | log__printf(mosq, MOSQ_LOG_DEBUG, "Received DISCONNECT (%d)", reason_code); 55 | 56 | do_client_disconnect(mosq, reason_code, properties); 57 | 58 | mosquitto_property_free_all(&properties); 59 | 60 | return MOSQ_ERR_SUCCESS; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea 42 | .idea/workspace.xml 43 | .idea/tasks.xml 44 | .idea/gradle.xml 45 | .idea/assetWizardSettings.xml 46 | .idea/dictionaries 47 | .idea/libraries 48 | # Android Studio 3 in .gitignore file. 49 | .idea/caches 50 | .idea/modules.xml 51 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 52 | .idea/navEditor.xml 53 | 54 | # Keystore files 55 | # Uncomment the following lines if you do not want to check your keystore files in. 56 | #*.jks 57 | #*.keystore 58 | 59 | # External native build folder generated in Android Studio 2.2 and later 60 | .externalNativeBuild 61 | .cxx/ 62 | 63 | # Google Services (e.g. APIs or Firebase) 64 | # google-services.json 65 | 66 | # Freeline 67 | freeline.py 68 | freeline/ 69 | freeline_project_description.json 70 | 71 | # fastlane 72 | fastlane/report.xml 73 | fastlane/Preview.html 74 | fastlane/screenshots 75 | fastlane/test_output 76 | fastlane/readme.md 77 | 78 | # Version control 79 | vcs.xml 80 | 81 | # lint 82 | lint/intermediates/ 83 | lint/generated/ 84 | lint/outputs/ 85 | lint/tmp/ 86 | # lint/reports/ 87 | 88 | .DS_Store 89 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/util_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef UTIL_MOSQ_H 17 | #define UTIL_MOSQ_H 18 | 19 | #include 20 | 21 | #include "tls_mosq.h" 22 | #include "mosquitto.h" 23 | #include "mosquitto_internal.h" 24 | #ifdef WITH_BROKER 25 | # include "mosquitto_broker_internal.h" 26 | #endif 27 | 28 | #ifdef WITH_BROKER 29 | int mosquitto__check_keepalive(struct mosquitto_db *db, struct mosquitto *mosq); 30 | #else 31 | int mosquitto__check_keepalive(struct mosquitto *mosq); 32 | #endif 33 | uint16_t mosquitto__mid_generate(struct mosquitto *mosq); 34 | FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read); 35 | 36 | int mosquitto__set_state(struct mosquitto *mosq, enum mosquitto_client_state state); 37 | enum mosquitto_client_state mosquitto__get_state(struct mosquitto *mosq); 38 | 39 | #ifdef WITH_TLS 40 | int mosquitto__hex2bin_sha1(const char *hex, unsigned char **bin); 41 | int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len); 42 | #endif 43 | 44 | int util__random_bytes(void *bytes, int count); 45 | 46 | void util__increment_receive_quota(struct mosquitto *mosq); 47 | void util__increment_send_quota(struct mosquitto *mosq); 48 | void util__decrement_receive_quota(struct mosquitto *mosq); 49 | void util__decrement_send_quota(struct mosquitto *mosq); 50 | #endif 51 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | /* ============================================================ 4 | * Platform options 5 | * ============================================================ */ 6 | 7 | #ifdef __APPLE__ 8 | # define __DARWIN_C_SOURCE 9 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__SYMBIAN32__) || defined(__QNX__) 10 | # define _XOPEN_SOURCE 700 11 | # define __BSD_VISIBLE 1 12 | # define HAVE_NETINET_IN_H 13 | #else 14 | # define _XOPEN_SOURCE 700 15 | # define _DEFAULT_SOURCE 1 16 | # define _POSIX_C_SOURCE 200809L 17 | #endif 18 | 19 | 20 | #ifndef _GNU_SOURCE 21 | # define _GNU_SOURCE 22 | #endif 23 | 24 | #define OPENSSL_LOAD_CONF 25 | 26 | /* ============================================================ 27 | * Compatibility defines 28 | * ============================================================ */ 29 | #if defined(_MSC_VER) && _MSC_VER < 1900 30 | # define snprintf sprintf_s 31 | # define EPROTO ECONNABORTED 32 | #endif 33 | 34 | #ifdef WIN32 35 | # ifndef strcasecmp 36 | # define strcasecmp strcmpi 37 | # endif 38 | # define strtok_r strtok_s 39 | # define strerror_r(e, b, l) strerror_s(b, l, e) 40 | #endif 41 | 42 | 43 | #define uthash_malloc(sz) mosquitto__malloc(sz) 44 | #define uthash_free(ptr,sz) mosquitto__free(ptr) 45 | 46 | 47 | #ifdef WITH_TLS 48 | # include 49 | # if defined(WITH_TLS_PSK) && !defined(OPENSSL_NO_PSK) 50 | # define FINAL_WITH_TLS_PSK 51 | # endif 52 | #endif 53 | 54 | 55 | #ifdef __COVERITY__ 56 | # include 57 | /* These are "wrong", but we don't use them so it doesn't matter */ 58 | # define _Float32 uint32_t 59 | # define _Float32x uint32_t 60 | # define _Float64 uint64_t 61 | # define _Float64x uint64_t 62 | # define _Float128 uint64_t 63 | #endif 64 | 65 | #define UNUSED(A) (void)(A) 66 | 67 | /* Android Bionic libpthread implementation doesn't have pthread_cancel */ 68 | #ifndef ANDROID 69 | # define HAVE_PTHREAD_CANCEL 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/handle_ping.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #ifdef WITH_BROKER 24 | # include "mosquitto_broker_internal.h" 25 | #endif 26 | 27 | #include "mosquitto.h" 28 | #include "logging_mosq.h" 29 | #include "memory_mosq.h" 30 | #include "messages_mosq.h" 31 | #include "mqtt_protocol.h" 32 | #include "net_mosq.h" 33 | #include "packet_mosq.h" 34 | #include "read_handle.h" 35 | #include "send_mosq.h" 36 | #include "util_mosq.h" 37 | 38 | int handle__pingreq(struct mosquitto *mosq) 39 | { 40 | int state; 41 | 42 | assert(mosq); 43 | 44 | state = mosquitto__get_state(mosq); 45 | if(state != mosq_cs_active){ 46 | return MOSQ_ERR_PROTOCOL; 47 | } 48 | 49 | #ifdef WITH_BROKER 50 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received PINGREQ from %s", mosq->id); 51 | #else 52 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PINGREQ", mosq->id); 53 | #endif 54 | return send__pingresp(mosq); 55 | } 56 | 57 | int handle__pingresp(struct mosquitto *mosq) 58 | { 59 | int state; 60 | 61 | assert(mosq); 62 | 63 | state = mosquitto__get_state(mosq); 64 | if(state != mosq_cs_active){ 65 | return MOSQ_ERR_PROTOCOL; 66 | } 67 | 68 | mosq->ping_t = 0; /* No longer waiting for a PINGRESP. */ 69 | #ifdef WITH_BROKER 70 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received PINGRESP from %s", mosq->id); 71 | #else 72 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PINGRESP", mosq->id); 73 | #endif 74 | return MOSQ_ERR_SUCCESS; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/read_handle.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "mosquitto.h" 24 | #include "logging_mosq.h" 25 | #include "memory_mosq.h" 26 | #include "messages_mosq.h" 27 | #include "mqtt_protocol.h" 28 | #include "net_mosq.h" 29 | #include "packet_mosq.h" 30 | #include "read_handle.h" 31 | #include "send_mosq.h" 32 | #include "time_mosq.h" 33 | #include "util_mosq.h" 34 | 35 | int handle__packet(struct mosquitto *mosq) 36 | { 37 | assert(mosq); 38 | 39 | switch((mosq->in_packet.command)&0xF0){ 40 | case CMD_PINGREQ: 41 | return handle__pingreq(mosq); 42 | case CMD_PINGRESP: 43 | return handle__pingresp(mosq); 44 | case CMD_PUBACK: 45 | return handle__pubackcomp(mosq, "PUBACK"); 46 | case CMD_PUBCOMP: 47 | return handle__pubackcomp(mosq, "PUBCOMP"); 48 | case CMD_PUBLISH: 49 | return handle__publish(mosq); 50 | case CMD_PUBREC: 51 | return handle__pubrec(NULL, mosq); 52 | case CMD_PUBREL: 53 | return handle__pubrel(NULL, mosq); 54 | case CMD_CONNACK: 55 | return handle__connack(mosq); 56 | case CMD_SUBACK: 57 | return handle__suback(mosq); 58 | case CMD_UNSUBACK: 59 | return handle__unsuback(mosq); 60 | case CMD_DISCONNECT: 61 | return handle__disconnect(mosq); 62 | case CMD_AUTH: 63 | return handle__auth(mosq); 64 | default: 65 | /* If we don't recognise the command, return an error straight away. */ 66 | log__printf(mosq, MOSQ_LOG_ERR, "Error: Unrecognised command %d\n", (mosq->in_packet.command)&0xF0); 67 | return MOSQ_ERR_PROTOCOL; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/send_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | #ifndef SEND_MOSQ_H 17 | #define SEND_MOSQ_H 18 | 19 | #include "mosquitto.h" 20 | #include "property_mosq.h" 21 | 22 | int send__simple_command(struct mosquitto *mosq, uint8_t command); 23 | int send__command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup, uint8_t reason_code, const mosquitto_property *properties); 24 | int send__real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval); 25 | 26 | int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session, const mosquitto_property *properties); 27 | int send__disconnect(struct mosquitto *mosq, uint8_t reason_code, const mosquitto_property *properties); 28 | int send__pingreq(struct mosquitto *mosq); 29 | int send__pingresp(struct mosquitto *mosq); 30 | int send__puback(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code); 31 | int send__pubcomp(struct mosquitto *mosq, uint16_t mid); 32 | int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval); 33 | int send__pubrec(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code); 34 | int send__pubrel(struct mosquitto *mosq, uint16_t mid); 35 | int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, int topic_qos, const mosquitto_property *properties); 36 | int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, const mosquitto_property *properties); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /library/src/main/jni/mosquitto/lib/alias_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019 Roger Light 3 | 4 | All rights reserved. This program and the accompanying materials 5 | are made available under the terms of the Eclipse Public License v1.0 6 | and Eclipse Distribution License v1.0 which accompany this distribution. 7 | 8 | The Eclipse Public License is available at 9 | http://www.eclipse.org/legal/epl-v10.html 10 | and the Eclipse Distribution License is available at 11 | http://www.eclipse.org/org/documents/edl-v10.php. 12 | 13 | Contributors: 14 | Roger Light - initial implementation and documentation. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include "mosquitto.h" 20 | #include "alias_mosq.h" 21 | #include "memory_mosq.h" 22 | 23 | int alias__add(struct mosquitto *mosq, const char *topic, int alias) 24 | { 25 | int i; 26 | struct mosquitto__alias *aliases; 27 | 28 | for(i=0; ialias_count; i++){ 29 | if(mosq->aliases[i].alias == alias){ 30 | mosquitto__free(mosq->aliases[i].topic); 31 | mosq->aliases[i].topic = mosquitto__strdup(topic); 32 | if(mosq->aliases[i].topic){ 33 | return MOSQ_ERR_SUCCESS; 34 | }else{ 35 | 36 | return MOSQ_ERR_NOMEM; 37 | } 38 | } 39 | } 40 | 41 | /* New alias */ 42 | aliases = mosquitto__realloc(mosq->aliases, sizeof(struct mosquitto__alias)*(mosq->alias_count+1)); 43 | if(!aliases) return MOSQ_ERR_NOMEM; 44 | 45 | mosq->aliases = aliases; 46 | mosq->aliases[mosq->alias_count].alias = alias; 47 | mosq->aliases[mosq->alias_count].topic = mosquitto__strdup(topic); 48 | if(!mosq->aliases[mosq->alias_count].topic){ 49 | return MOSQ_ERR_NOMEM; 50 | } 51 | mosq->alias_count++; 52 | 53 | return MOSQ_ERR_SUCCESS; 54 | } 55 | 56 | 57 | int alias__find(struct mosquitto *mosq, char **topic, int alias) 58 | { 59 | int i; 60 | 61 | for(i=0; ialias_count; i++){ 62 | if(mosq->aliases[i].alias == alias){ 63 | *topic = mosquitto__strdup(mosq->aliases[i].topic); 64 | if(*topic){ 65 | return MOSQ_ERR_SUCCESS; 66 | }else{ 67 | return MOSQ_ERR_NOMEM; 68 | } 69 | } 70 | } 71 | return MOSQ_ERR_INVAL; 72 | } 73 | 74 | 75 | void alias__free_all(struct mosquitto *mosq) 76 | { 77 | int i; 78 | 79 | for(i=0; ialias_count; i++){ 80 | mosquitto__free(mosq->aliases[i].topic); 81 | } 82 | mosquitto__free(mosq->aliases); 83 | mosq->aliases = NULL; 84 | mosq->alias_count = 0; 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |