├── 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 |
20 |
21 |
32 |
33 |
44 |
45 |
56 |
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/packet_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 PACKET_MOSQ_H
17 | #define PACKET_MOSQ_H
18 |
19 | #include "mosquitto_internal.h"
20 | #include "mosquitto.h"
21 |
22 | #ifdef WITH_BROKER
23 | struct mosquitto_db;
24 | #endif
25 |
26 | int packet__alloc(struct mosquitto__packet *packet);
27 | void packet__cleanup(struct mosquitto__packet *packet);
28 | void packet__cleanup_all(struct mosquitto *mosq);
29 | int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet);
30 |
31 | int packet__check_oversize(struct mosquitto *mosq, uint32_t remaining_length);
32 |
33 | int packet__read_byte(struct mosquitto__packet *packet, uint8_t *byte);
34 | int packet__read_bytes(struct mosquitto__packet *packet, void *bytes, uint32_t count);
35 | int packet__read_binary(struct mosquitto__packet *packet, uint8_t **data, int *length);
36 | int packet__read_string(struct mosquitto__packet *packet, char **str, int *length);
37 | int packet__read_uint16(struct mosquitto__packet *packet, uint16_t *word);
38 | int packet__read_uint32(struct mosquitto__packet *packet, uint32_t *word);
39 | int packet__read_varint(struct mosquitto__packet *packet, int32_t *word, int8_t *bytes);
40 |
41 | void packet__write_byte(struct mosquitto__packet *packet, uint8_t byte);
42 | void packet__write_bytes(struct mosquitto__packet *packet, const void *bytes, uint32_t count);
43 | void packet__write_string(struct mosquitto__packet *packet, const char *str, uint16_t length);
44 | void packet__write_uint16(struct mosquitto__packet *packet, uint16_t word);
45 | void packet__write_uint32(struct mosquitto__packet *packet, uint32_t word);
46 | int packet__write_varint(struct mosquitto__packet *packet, int32_t word);
47 |
48 | int packet__varint_bytes(int32_t word);
49 |
50 | int packet__write(struct mosquitto *mosq);
51 | #ifdef WITH_BROKER
52 | int packet__read(struct mosquitto_db *db, struct mosquitto *mosq);
53 | #else
54 | int packet__read(struct mosquitto *mosq);
55 | #endif
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/send_disconnect.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 |
21 | #ifdef WITH_BROKER
22 | # include "mosquitto_broker_internal.h"
23 | #endif
24 |
25 | #include "mosquitto.h"
26 | #include "mosquitto_internal.h"
27 | #include "logging_mosq.h"
28 | #include "memory_mosq.h"
29 | #include "mqtt_protocol.h"
30 | #include "packet_mosq.h"
31 | #include "property_mosq.h"
32 | #include "send_mosq.h"
33 |
34 |
35 | int send__disconnect(struct mosquitto *mosq, uint8_t reason_code, const mosquitto_property *properties)
36 | {
37 | struct mosquitto__packet *packet = NULL;
38 | int rc;
39 | int proplen, varbytes;
40 |
41 | assert(mosq);
42 | #ifdef WITH_BROKER
43 | # ifdef WITH_BRIDGE
44 | if(mosq->bridge){
45 | log__printf(mosq, MOSQ_LOG_DEBUG, "Bridge %s sending DISCONNECT", mosq->id);
46 | }else
47 | # else
48 | {
49 | log__printf(mosq, MOSQ_LOG_DEBUG, "Sending DISCONNECT to %s (rc%d)", mosq->id, reason_code);
50 | }
51 | # endif
52 | #else
53 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending DISCONNECT", mosq->id);
54 | #endif
55 | assert(mosq);
56 | packet = mosquitto__calloc(1, sizeof(struct mosquitto__packet));
57 | if(!packet) return MOSQ_ERR_NOMEM;
58 |
59 | packet->command = CMD_DISCONNECT;
60 | if(mosq->protocol == mosq_p_mqtt5 && (reason_code != 0 || properties)){
61 | packet->remaining_length = 1;
62 | if(properties){
63 | proplen = property__get_length_all(properties);
64 | varbytes = packet__varint_bytes(proplen);
65 | packet->remaining_length += proplen + varbytes;
66 | }
67 | }else{
68 | packet->remaining_length = 0;
69 | }
70 |
71 | rc = packet__alloc(packet);
72 | if(rc){
73 | mosquitto__free(packet);
74 | return rc;
75 | }
76 | if(mosq->protocol == mosq_p_mqtt5 && (reason_code != 0 || properties)){
77 | packet__write_byte(packet, reason_code);
78 | if(properties){
79 | property__write_all(packet, properties, true);
80 | }
81 | }
82 |
83 | return packet__queue(mosq, packet);
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/handle_unsuback.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 "property_mosq.h"
35 | #include "read_handle.h"
36 | #include "send_mosq.h"
37 | #include "util_mosq.h"
38 |
39 |
40 | int handle__unsuback(struct mosquitto *mosq)
41 | {
42 | uint16_t mid;
43 | int rc;
44 | mosquitto_property *properties = NULL;
45 | int state;
46 |
47 | assert(mosq);
48 |
49 | state = mosquitto__get_state(mosq);
50 | if(state != mosq_cs_active){
51 | return MOSQ_ERR_PROTOCOL;
52 | }
53 |
54 | #ifdef WITH_BROKER
55 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBACK from %s", mosq->id);
56 | #else
57 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received UNSUBACK", mosq->id);
58 | #endif
59 | rc = packet__read_uint16(&mosq->in_packet, &mid);
60 | if(rc) return rc;
61 | if(mid == 0) return MOSQ_ERR_PROTOCOL;
62 |
63 | if(mosq->protocol == mosq_p_mqtt5){
64 | rc = property__read_all(CMD_UNSUBACK, &mosq->in_packet, &properties);
65 | if(rc) return rc;
66 | }
67 |
68 | #ifdef WITH_BROKER
69 | /* Immediately free, we don't do anything with Reason String or User Property at the moment */
70 | mosquitto_property_free_all(&properties);
71 | #else
72 | pthread_mutex_lock(&mosq->callback_mutex);
73 | if(mosq->on_unsubscribe){
74 | mosq->in_callback = true;
75 | mosq->on_unsubscribe(mosq, mosq->userdata, mid);
76 | mosq->in_callback = false;
77 | }
78 | if(mosq->on_unsubscribe_v5){
79 | mosq->in_callback = true;
80 | mosq->on_unsubscribe_v5(mosq, mosq->userdata, mid, properties);
81 | mosq->in_callback = false;
82 | }
83 | pthread_mutex_unlock(&mosq->callback_mutex);
84 | mosquitto_property_free_all(&properties);
85 | #endif
86 |
87 | return MOSQ_ERR_SUCCESS;
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/comp.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef HEADER_COMP_H
3 | # define HEADER_COMP_H
4 |
5 | # include
6 |
7 | # ifdef OPENSSL_NO_COMP
8 | # error COMP is disabled.
9 | # endif
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif
14 |
15 | typedef struct comp_ctx_st COMP_CTX;
16 |
17 | struct comp_method_st {
18 | int type; /* NID for compression library */
19 | const char *name; /* A text string to identify the library */
20 | int (*init) (COMP_CTX *ctx);
21 | void (*finish) (COMP_CTX *ctx);
22 | int (*compress) (COMP_CTX *ctx,
23 | unsigned char *out, unsigned int olen,
24 | unsigned char *in, unsigned int ilen);
25 | int (*expand) (COMP_CTX *ctx,
26 | unsigned char *out, unsigned int olen,
27 | unsigned char *in, unsigned int ilen);
28 | /*
29 | * The following two do NOTHING, but are kept for backward compatibility
30 | */
31 | long (*ctrl) (void);
32 | long (*callback_ctrl) (void);
33 | };
34 |
35 | struct comp_ctx_st {
36 | COMP_METHOD *meth;
37 | unsigned long compress_in;
38 | unsigned long compress_out;
39 | unsigned long expand_in;
40 | unsigned long expand_out;
41 | CRYPTO_EX_DATA ex_data;
42 | };
43 |
44 | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
45 | void COMP_CTX_free(COMP_CTX *ctx);
46 | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
47 | unsigned char *in, int ilen);
48 | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
49 | unsigned char *in, int ilen);
50 | COMP_METHOD *COMP_rle(void);
51 | COMP_METHOD *COMP_zlib(void);
52 | void COMP_zlib_cleanup(void);
53 |
54 | # ifdef HEADER_BIO_H
55 | # ifdef ZLIB
56 | BIO_METHOD *BIO_f_zlib(void);
57 | # endif
58 | # endif
59 |
60 | /* BEGIN ERROR CODES */
61 | /*
62 | * The following lines are auto generated by the script mkerr.pl. Any changes
63 | * made after this point may be overwritten when the script is next run.
64 | */
65 | void ERR_load_COMP_strings(void);
66 |
67 | /* Error codes for the COMP functions. */
68 |
69 | /* Function codes. */
70 | # define COMP_F_BIO_ZLIB_FLUSH 99
71 | # define COMP_F_BIO_ZLIB_NEW 100
72 | # define COMP_F_BIO_ZLIB_READ 101
73 | # define COMP_F_BIO_ZLIB_WRITE 102
74 |
75 | /* Reason codes. */
76 | # define COMP_R_ZLIB_DEFLATE_ERROR 99
77 | # define COMP_R_ZLIB_INFLATE_ERROR 100
78 | # define COMP_R_ZLIB_NOT_SUPPORTED 101
79 |
80 | #ifdef __cplusplus
81 | }
82 | #endif
83 | #endif
84 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto_wrapper.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Key.Yao on 2020-02-21.
3 | //
4 |
5 | #ifndef MQTT_CLIENT_ANDROID_MOSQUITTO_WRAPPER_H
6 | #define MQTT_CLIENT_ANDROID_MOSQUITTO_WRAPPER_H
7 |
8 | #include "mosquitto.h"
9 |
10 | namespace mqttclient {
11 |
12 | typedef void(*MOSQ_CONNECT_CALLBACK)(void *instance, int rc);
13 | typedef void(*MOSQ_CONNECT_WITH_FLAG_CALLBACK)(void *instance, int rc, int flags);
14 | typedef void(*MOSQ_DISCONNECT_CALLBACK)(void *instance, int rc);
15 | typedef void(*MOSQ_PUBLISH_CALLBACK)(void *instance, int mid);
16 | typedef void(*MOSQ_MESSAGE_CALLBACK)(void *instance, const struct mosquitto_message * message);
17 | typedef void(*MOSQ_SUBSCRIBE_CALLBACK)(void *instance, int mid, int qos_count, const int * granted_qos);
18 | typedef void(*MOSQ_UNSUBSCRIBE_CALLBACK)(void *instance, int mid);
19 | typedef void(*MOSQ_LOG_CALLBACK)(void *instance, int level, const char * str);
20 |
21 | int lib_init();
22 | int lib_cleanup();
23 | const char * strerror(int mosq_errno);
24 |
25 | class mosquitto_wrapper {
26 |
27 | public:
28 | mosquitto_wrapper(const char *id = NULL, bool clean_session = true);
29 | ~mosquitto_wrapper();
30 |
31 | // 附加数据
32 | void *extra;
33 |
34 | MOSQ_CONNECT_CALLBACK on_connect_callback = NULL;
35 | MOSQ_CONNECT_WITH_FLAG_CALLBACK on_connect_with_flag_callback = NULL;
36 | MOSQ_DISCONNECT_CALLBACK on_disconnect_callback = NULL;
37 | MOSQ_PUBLISH_CALLBACK on_publish_callback = NULL;
38 | MOSQ_MESSAGE_CALLBACK on_message_callback = NULL;
39 | MOSQ_SUBSCRIBE_CALLBACK on_subscribe_callback = NULL;
40 | MOSQ_UNSUBSCRIBE_CALLBACK on_unsubscribe_callback = NULL;
41 | MOSQ_LOG_CALLBACK on_log_callback = NULL;
42 |
43 |
44 | int connect(const char *host, int port = 1883, int keepalive = 60);
45 | int reconnect();
46 | int disconnect();
47 | int publish(int *mid, const char *topic, int payloadlen = 0, const void *payload = NULL, int qos = 0, bool retain = false);
48 | int subscribe(int *mid, const char *sub, int qos = 0);
49 | int unsubscribe(int *mid, const char *sub);
50 | int username_pw_set(const char *username, const char *password = NULL);
51 | int tls_set(const char *cafile, const char *capath = NULL, const char *certfile = NULL, const char *keyfile = NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata) = NULL);
52 | int tls_opts_set(int cert_reqs, const char *tls_version = NULL, const char *ciphers = NULL);
53 | int tls_insecure_set(bool value);
54 |
55 | int loop(int timeout = -1, int max_packets = 1);
56 |
57 | private:
58 | struct mosquitto *m_mosq;
59 | };
60 |
61 | }
62 |
63 |
64 | #endif //MQTT_CLIENT_ANDROID_MOSQUITTO_WRAPPER_H
65 |
--------------------------------------------------------------------------------
/library/src/main/jni/JNIEnvHandler.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Key.Yao on 2020-02-20.
3 | //
4 |
5 | #include "JNIEnvHandler.h"
6 |
7 | using namespace std;
8 |
9 | struct ThreadMessage {
10 | ThreadMessage(int i, void* m, bool flag) {
11 | what = i;
12 | msg = m;
13 | exit = flag;
14 | }
15 | int what;
16 | void* msg;
17 | bool exit;
18 | };
19 |
20 | JNIEnvHandler::JNIEnvHandler(const char *threadName) {
21 | _threadName = threadName;
22 | _thread = nullptr;
23 | _exitFlag = false;
24 | _vm = nullptr;
25 | _callback = nullptr;
26 | }
27 |
28 | JNIEnvHandler::~JNIEnvHandler() {
29 | _thread = nullptr;
30 | _callback = nullptr;
31 | _instance = nullptr;
32 | _vm = nullptr;
33 | }
34 |
35 | bool JNIEnvHandler::init(JavaVM *vm, jobject instance, handleMessage callback) {
36 | if (!_thread) {
37 | _thread = new thread(&JNIEnvHandler::process, this);
38 | }
39 | _vm = vm;
40 | _instance = instance;
41 | _callback = callback;
42 | return true;
43 | }
44 |
45 | void JNIEnvHandler::exit() {
46 | if (!_thread) {
47 | return;
48 | }
49 |
50 | auto *msg = new ThreadMessage(-1, nullptr, true);
51 |
52 | {
53 | lock_guard lock(_mutex);
54 | _queue.push(msg);
55 | _cv.notify_one();
56 | }
57 |
58 | _thread->join();
59 | delete _thread;
60 | _thread = nullptr;
61 | _exitFlag = true;
62 | }
63 |
64 | std::thread::id JNIEnvHandler::getThreadId() {
65 | return _thread->get_id();
66 | }
67 |
68 | void JNIEnvHandler::post(int what, void *obj) {
69 | auto *msg = new ThreadMessage(what, obj, false);
70 | unique_lock lock(_mutex);
71 | _queue.push(msg);
72 | _cv.notify_one();
73 | }
74 |
75 | void JNIEnvHandler::process() {
76 | _exitFlag = false;
77 |
78 | JNIEnv *env = nullptr;
79 | if (_vm) {
80 | _vm->AttachCurrentThread(&env, nullptr);
81 | }
82 |
83 | while (true) {
84 | ThreadMessage *msg = nullptr;
85 | {
86 | unique_lock lock(_mutex);
87 | while (_queue.empty()) {
88 | _cv.wait(lock);
89 | }
90 |
91 | if (_queue.empty()) {
92 | continue;
93 | }
94 |
95 | msg = _queue.front();
96 | _queue.pop();
97 |
98 | }
99 |
100 | if (msg->exit) {
101 | delete msg;
102 | break;
103 | }
104 |
105 | if (env && _instance) {
106 | _callback(msg->what, msg->msg, env, _instance);
107 | }
108 |
109 | delete msg;
110 | }
111 |
112 | env->DeleteGlobalRef(_instance);
113 |
114 | if (_vm) {
115 | _vm->DetachCurrentThread();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/send_subscribe.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 |
22 | #ifdef WITH_BROKER
23 | # include "mosquitto_broker_internal.h"
24 | #endif
25 |
26 | #include "mosquitto.h"
27 | #include "mosquitto_internal.h"
28 | #include "logging_mosq.h"
29 | #include "memory_mosq.h"
30 | #include "mqtt_protocol.h"
31 | #include "packet_mosq.h"
32 | #include "property_mosq.h"
33 | #include "util_mosq.h"
34 |
35 |
36 | int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, const char **topic, int topic_qos, const mosquitto_property *properties)
37 | {
38 | struct mosquitto__packet *packet = NULL;
39 | uint32_t packetlen;
40 | uint16_t local_mid;
41 | int rc;
42 | int i;
43 | int proplen, varbytes;
44 |
45 | assert(mosq);
46 | assert(topic);
47 |
48 | packet = mosquitto__calloc(1, sizeof(struct mosquitto__packet));
49 | if(!packet) return MOSQ_ERR_NOMEM;
50 |
51 | packetlen = 2;
52 | if(mosq->protocol == mosq_p_mqtt5){
53 | proplen = property__get_length_all(properties);
54 | varbytes = packet__varint_bytes(proplen);
55 | packetlen += proplen + varbytes;
56 | }
57 | for(i=0; icommand = CMD_SUBSCRIBE | (1<<1);
62 | packet->remaining_length = packetlen;
63 | rc = packet__alloc(packet);
64 | if(rc){
65 | mosquitto__free(packet);
66 | return rc;
67 | }
68 |
69 | /* Variable header */
70 | local_mid = mosquitto__mid_generate(mosq);
71 | if(mid) *mid = (int)local_mid;
72 | packet__write_uint16(packet, local_mid);
73 |
74 | if(mosq->protocol == mosq_p_mqtt5){
75 | property__write_all(packet, properties, true);
76 | }
77 |
78 | /* Payload */
79 | for(i=0; iid, local_mid, topic[0], topic_qos&0x03, topic_qos&0xFC);
87 | # endif
88 | #else
89 | for(i=0; iid, local_mid, topic[i], topic_qos&0x03, topic_qos&0xFC);
91 | }
92 | #endif
93 |
94 | return packet__queue(mosq, packet);
95 | }
96 |
97 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/net_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 NET_MOSQ_H
17 | #define NET_MOSQ_H
18 |
19 | #ifndef WIN32
20 | # include
21 | #else
22 | # include
23 | # ifndef _SSIZE_T_DEFINED
24 | typedef SSIZE_T ssize_t;
25 | # define _SSIZE_T_DEFINED
26 | # endif
27 | #endif
28 |
29 | #include "mosquitto_internal.h"
30 | #include "mosquitto.h"
31 |
32 | #ifdef WITH_BROKER
33 | struct mosquitto_db;
34 | #endif
35 |
36 | #ifdef WIN32
37 | # define COMPAT_CLOSE(a) closesocket(a)
38 | # define COMPAT_ECONNRESET WSAECONNRESET
39 | # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK
40 | #else
41 | # define COMPAT_CLOSE(a) close(a)
42 | # define COMPAT_ECONNRESET ECONNRESET
43 | # define COMPAT_EWOULDBLOCK EWOULDBLOCK
44 | #endif
45 |
46 | /* For when not using winsock libraries. */
47 | #ifndef INVALID_SOCKET
48 | #define INVALID_SOCKET -1
49 | #endif
50 |
51 | /* Macros for accessing the MSB and LSB of a uint16_t */
52 | #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8)
53 | #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF)
54 |
55 | int net__init(void);
56 | void net__cleanup(void);
57 |
58 | int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking);
59 | #ifdef WITH_BROKER
60 | int net__socket_close(struct mosquitto_db *db, struct mosquitto *mosq);
61 | #else
62 | int net__socket_close(struct mosquitto *mosq);
63 | #endif
64 | int net__try_connect(const char *host, uint16_t port, mosq_sock_t *sock, const char *bind_address, bool blocking);
65 | int net__try_connect_step1(struct mosquitto *mosq, const char *host);
66 | int net__try_connect_step2(struct mosquitto *mosq, uint16_t port, mosq_sock_t *sock);
67 | int net__socket_connect_step3(struct mosquitto *mosq, const char *host);
68 | int net__socket_nonblock(mosq_sock_t *sock);
69 | int net__socketpair(mosq_sock_t *sp1, mosq_sock_t *sp2);
70 |
71 | ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count);
72 | ssize_t net__write(struct mosquitto *mosq, void *buf, size_t count);
73 |
74 | #ifdef WITH_TLS
75 | int net__socket_apply_tls(struct mosquitto *mosq);
76 | int net__socket_connect_tls(struct mosquitto *mosq);
77 | int mosquitto__verify_ocsp_status_cb(SSL * ssl, void *arg);
78 | UI_METHOD *net__get_ui_method(void);
79 | #define ENGINE_FINISH(e) if(e) ENGINE_finish(e)
80 | #define ENGINE_SECRET_MODE "SECRET_MODE"
81 | #define ENGINE_SECRET_MODE_SHA 0x1000
82 | #define ENGINE_PIN "PIN"
83 | #endif
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/send_unsubscribe.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 |
22 | #ifdef WITH_BROKER
23 | # include "mosquitto_broker_internal.h"
24 | #endif
25 |
26 | #include "mosquitto.h"
27 | #include "logging_mosq.h"
28 | #include "memory_mosq.h"
29 | #include "mqtt_protocol.h"
30 | #include "packet_mosq.h"
31 | #include "property_mosq.h"
32 | #include "send_mosq.h"
33 | #include "util_mosq.h"
34 |
35 |
36 | int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, const mosquitto_property *properties)
37 | {
38 | /* FIXME - only deals with a single topic */
39 | struct mosquitto__packet *packet = NULL;
40 | uint32_t packetlen;
41 | uint16_t local_mid;
42 | int rc;
43 | int proplen, varbytes;
44 | int i;
45 |
46 | assert(mosq);
47 | assert(topic);
48 |
49 | packet = mosquitto__calloc(1, sizeof(struct mosquitto__packet));
50 | if(!packet) return MOSQ_ERR_NOMEM;
51 |
52 | packetlen = 2;
53 |
54 | for(i=0; iprotocol == mosq_p_mqtt5){
58 | proplen = property__get_length_all(properties);
59 | varbytes = packet__varint_bytes(proplen);
60 | packetlen += proplen + varbytes;
61 | }
62 |
63 | packet->command = CMD_UNSUBSCRIBE | (1<<1);
64 | packet->remaining_length = packetlen;
65 | rc = packet__alloc(packet);
66 | if(rc){
67 | mosquitto__free(packet);
68 | return rc;
69 | }
70 |
71 | /* Variable header */
72 | local_mid = mosquitto__mid_generate(mosq);
73 | if(mid) *mid = (int)local_mid;
74 | packet__write_uint16(packet, local_mid);
75 |
76 | if(mosq->protocol == mosq_p_mqtt5){
77 | /* We don't use User Property yet. */
78 | property__write_all(packet, properties, true);
79 | }
80 |
81 | /* Payload */
82 | for(i=0; iid, local_mid, topic[i]);
90 | }
91 | # endif
92 | #else
93 | for(i=0; iid, local_mid, topic[i]);
95 | }
96 | #endif
97 | return packet__queue(mosq, packet);
98 | }
99 |
100 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/pem2.h:
--------------------------------------------------------------------------------
1 | /* ====================================================================
2 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | *
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | *
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in
13 | * the documentation and/or other materials provided with the
14 | * distribution.
15 | *
16 | * 3. All advertising materials mentioning features or use of this
17 | * software must display the following acknowledgment:
18 | * "This product includes software developed by the OpenSSL Project
19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 | *
21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 | * endorse or promote products derived from this software without
23 | * prior written permission. For written permission, please contact
24 | * licensing@OpenSSL.org.
25 | *
26 | * 5. Products derived from this software may not be called "OpenSSL"
27 | * nor may "OpenSSL" appear in their names without prior written
28 | * permission of the OpenSSL Project.
29 | *
30 | * 6. Redistributions of any form whatsoever must retain the following
31 | * acknowledgment:
32 | * "This product includes software developed by the OpenSSL Project
33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 | *
35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 | * OF THE POSSIBILITY OF SUCH DAMAGE.
47 | * ====================================================================
48 | *
49 | * This product includes cryptographic software written by Eric Young
50 | * (eay@cryptsoft.com). This product includes software written by Tim
51 | * Hudson (tjh@cryptsoft.com).
52 | *
53 | */
54 |
55 | /*
56 | * This header only exists to break a circular dependency between pem and err
57 | * Ben 30 Jan 1999.
58 | */
59 |
60 | #ifdef __cplusplus
61 | extern "C" {
62 | #endif
63 |
64 | #ifndef HEADER_PEM_H
65 | void ERR_load_PEM_strings(void);
66 | #endif
67 |
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/handle_suback.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 |
21 | #ifdef WITH_BROKER
22 | # include "mosquitto_broker_internal.h"
23 | #endif
24 |
25 | #include "mosquitto.h"
26 | #include "mosquitto_internal.h"
27 | #include "logging_mosq.h"
28 | #include "memory_mosq.h"
29 | #include "mqtt_protocol.h"
30 | #include "packet_mosq.h"
31 | #include "property_mosq.h"
32 | #include "util_mosq.h"
33 |
34 |
35 | int handle__suback(struct mosquitto *mosq)
36 | {
37 | uint16_t mid;
38 | uint8_t qos;
39 | int *granted_qos;
40 | int qos_count;
41 | int i = 0;
42 | int rc;
43 | mosquitto_property *properties = NULL;
44 | int state;
45 |
46 | assert(mosq);
47 |
48 | state = mosquitto__get_state(mosq);
49 | if(state != mosq_cs_active){
50 | return MOSQ_ERR_PROTOCOL;
51 | }
52 |
53 | #ifdef WITH_BROKER
54 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received SUBACK from %s", mosq->id);
55 | #else
56 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received SUBACK", mosq->id);
57 | #endif
58 | rc = packet__read_uint16(&mosq->in_packet, &mid);
59 | if(rc) return rc;
60 | if(mid == 0) return MOSQ_ERR_PROTOCOL;
61 |
62 | if(mosq->protocol == mosq_p_mqtt5){
63 | rc = property__read_all(CMD_SUBACK, &mosq->in_packet, &properties);
64 | if(rc) return rc;
65 | }
66 |
67 | qos_count = mosq->in_packet.remaining_length - mosq->in_packet.pos;
68 | granted_qos = mosquitto__malloc(qos_count*sizeof(int));
69 | if(!granted_qos) return MOSQ_ERR_NOMEM;
70 | while(mosq->in_packet.pos < mosq->in_packet.remaining_length){
71 | rc = packet__read_byte(&mosq->in_packet, &qos);
72 | if(rc){
73 | mosquitto__free(granted_qos);
74 | return rc;
75 | }
76 | granted_qos[i] = (int)qos;
77 | i++;
78 | }
79 | #ifdef WITH_BROKER
80 | /* Immediately free, we don't do anything with Reason String or User Property at the moment */
81 | mosquitto_property_free_all(&properties);
82 | #else
83 | pthread_mutex_lock(&mosq->callback_mutex);
84 | if(mosq->on_subscribe){
85 | mosq->in_callback = true;
86 | mosq->on_subscribe(mosq, mosq->userdata, mid, qos_count, granted_qos);
87 | mosq->in_callback = false;
88 | }
89 | if(mosq->on_subscribe_v5){
90 | mosq->in_callback = true;
91 | mosq->on_subscribe_v5(mosq, mosq->userdata, mid, qos_count, granted_qos, properties);
92 | mosq->in_callback = false;
93 | }
94 | pthread_mutex_unlock(&mosq->callback_mutex);
95 | mosquitto_property_free_all(&properties);
96 | #endif
97 | mosquitto__free(granted_qos);
98 |
99 | return MOSQ_ERR_SUCCESS;
100 | }
101 |
102 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Mqtt Client
2 | 基于[mosquitto](https://github.com/eclipse/mosquitto)的android mqtt客户端
3 | * 使用[mosquitto/lib](https://github.com/eclipse/mosquitto/tree/master/lib)的代码,用c++封装接口
4 | * 对外提供java接口,简单易用
5 | * 支持OpenSSL加密
6 | * 实现订阅、解除订阅、发布消息等功能
7 |
8 | ## 接口
9 | MqttClient.java
10 | ```java
11 | /**
12 | * 获取单例
13 | */
14 | public static MqttClient getInstance()
15 | ```
16 | ```java
17 | /**
18 | * 启动mqtt服务
19 | */
20 | public void start(@NonNull String host, int port, @NonNull String uuid, boolean clearSession)
21 | public void start(@NonNull String host, int port, @NonNull String uuid, boolean clearSession, @NonNull String caFilePath, @NonNull String username, @NonNull String password)
22 | ```
23 | ```java
24 | /**
25 | * 重连服务
26 | */
27 | public void reconnect()
28 | ```
29 | ```java
30 | /**
31 | * 订阅主题
32 | */
33 | public void subscribe(String topic)
34 | public void subscribe(String topic, int qos)
35 | public void subscribe(List topicList)
36 | public void subscribe(List topicList, List qosList)
37 | ```
38 | ```java
39 | /**
40 | * 解除订阅
41 | */
42 | public void unsubscribe(String topic)
43 | public void unsubscribe(List topicList)
44 | ```
45 | ```java
46 | /**
47 | * 发布消息
48 | */
49 | public void publish(String topic, String message)
50 | public void publish(String topic, String message, int qos)
51 | ```
52 | ```java
53 | /**
54 | * mqtt事件回调接口
55 | */
56 | public interface MqttCallback {
57 | @WorkerThread
58 | void onMessage(@NonNull String topic, @NonNull String message);
59 | @WorkerThread
60 | void onLog(String str);
61 | }
62 | ```
63 | ```java
64 | /**
65 | * 设置mqtt事件回调
66 | */
67 | public void setOnMqttCallback(@Nullable MqttCallback callback)
68 | ```
69 |
70 | ## 使用
71 | ```
72 | - 导入Module: Android Studio -> File -> New -> Import Module -> 选中“library”文件夹
73 |
74 | - 修改app/build.gradle文件,添加ndk abiFilters设置
75 | android {
76 | ...
77 | defaultConfig {
78 | ...
79 | ndk {
80 | abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a'
81 | }
82 | }
83 | }
84 |
85 | - 添加依赖
86 | dependencies {
87 | implementation project(':library')
88 | }
89 | ```
90 |
91 | ## 编译问题
92 | 因为默认支持OpenSSL,依赖静态库只添加了三个abi版本,所以项目编译默认只支持```'armeabi-v7a', 'x86', 'arm64-v8a'```,如需支持其他cpu abi,请自行编译OpenSSL静态库
93 | * 把```libssl.a libcrypto.a```文件添加到```/library/src/main/jni/lib```目录下,并用文件夹区分abi类型
94 | * 修改```library/build.gradle```,添加对应的abi类型
95 | * 修改```app/build.gradle```,添加对应的abi类型
96 |
97 | ## 禁用OpenSSL
98 | 修改```/library/src/main/jni/Android.mk```文件,注释掉下面的代码
99 | ```
100 | ...
101 |
102 | # ssl lib
103 | #include $(CLEAR_VARS)
104 | #LOCAL_MODULE := ssl
105 | #LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libssl.a
106 | #include $(PREBUILT_STATIC_LIBRARY)
107 |
108 | # crypto lib
109 | #include $(CLEAR_VARS)
110 | #LOCAL_MODULE := ssl_crypto
111 | #LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libcrypto.a
112 | #include $(PREBUILT_STATIC_LIBRARY)
113 |
114 | ...
115 |
116 | #LOCAL_CFLAGS += -DWITH_TLS_PSK
117 | #LOCAL_CFLAGS += -DWITH_TLS
118 |
119 | ...
120 |
121 | # link lib
122 | #LOCAL_STATIC_LIBRARIES := ssl ssl_crypto
123 |
124 | ...
125 | ```
126 |
127 | ## 例子
128 | app module只实现了简单的调用,相关日志输出到了logcat
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/srv_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 WITH_SRV
20 | # include
21 |
22 | # include
23 | # include
24 | # include
25 | #endif
26 |
27 | #include "logging_mosq.h"
28 | #include "memory_mosq.h"
29 | #include "mosquitto_internal.h"
30 | #include "mosquitto.h"
31 | #include "util_mosq.h"
32 |
33 | #ifdef WITH_SRV
34 | static void srv_callback(void *arg, int status, int timeouts, unsigned char *abuf, int alen)
35 | {
36 | struct mosquitto *mosq = arg;
37 | struct ares_srv_reply *reply = NULL;
38 | if(status == ARES_SUCCESS){
39 | status = ares_parse_srv_reply(abuf, alen, &reply);
40 | if(status == ARES_SUCCESS){
41 | // FIXME - choose which answer to use based on rfc2782 page 3. */
42 | mosquitto_connect(mosq, reply->host, reply->port, mosq->keepalive);
43 | }
44 | }else{
45 | log__printf(mosq, MOSQ_LOG_ERR, "Error: SRV lookup failed (%d).", status);
46 | /* FIXME - calling on_disconnect here isn't correct. */
47 | pthread_mutex_lock(&mosq->callback_mutex);
48 | if(mosq->on_disconnect){
49 | mosq->in_callback = true;
50 | mosq->on_disconnect(mosq, mosq->userdata, MOSQ_ERR_LOOKUP);
51 | mosq->in_callback = false;
52 | }
53 | if(mosq->on_disconnect_v5){
54 | mosq->in_callback = true;
55 | mosq->on_disconnect_v5(mosq, mosq->userdata, MOSQ_ERR_LOOKUP, NULL);
56 | mosq->in_callback = false;
57 | }
58 | pthread_mutex_unlock(&mosq->callback_mutex);
59 | }
60 | }
61 | #endif
62 |
63 | int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address)
64 | {
65 | #ifdef WITH_SRV
66 | char *h;
67 | int rc;
68 | if(!mosq) return MOSQ_ERR_INVAL;
69 |
70 | rc = ares_init(&mosq->achan);
71 | if(rc != ARES_SUCCESS){
72 | return MOSQ_ERR_UNKNOWN;
73 | }
74 |
75 | if(!host){
76 | // get local domain
77 | }else{
78 | #ifdef WITH_TLS
79 | if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk){
80 | h = mosquitto__malloc(strlen(host) + strlen("_secure-mqtt._tcp.") + 1);
81 | if(!h) return MOSQ_ERR_NOMEM;
82 | sprintf(h, "_secure-mqtt._tcp.%s", host);
83 | }else{
84 | #endif
85 | h = mosquitto__malloc(strlen(host) + strlen("_mqtt._tcp.") + 1);
86 | if(!h) return MOSQ_ERR_NOMEM;
87 | sprintf(h, "_mqtt._tcp.%s", host);
88 | #ifdef WITH_TLS
89 | }
90 | #endif
91 | ares_search(mosq->achan, h, ns_c_in, ns_t_srv, srv_callback, mosq);
92 | mosquitto__free(h);
93 | }
94 |
95 | mosquitto__set_state(mosq, mosq_cs_connect_srv);
96 |
97 | mosq->keepalive = keepalive;
98 |
99 | return MOSQ_ERR_SUCCESS;
100 |
101 | #else
102 | UNUSED(mosq);
103 | UNUSED(host);
104 | UNUSED(keepalive);
105 | UNUSED(bind_address);
106 |
107 | return MOSQ_ERR_NOT_SUPPORTED;
108 | #endif
109 | }
110 |
111 |
112 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/thread_mosq.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2011-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 | #ifndef WIN32
20 | #include
21 | #endif
22 |
23 | #include "mosquitto_internal.h"
24 | #include "net_mosq.h"
25 | #include "util_mosq.h"
26 |
27 | void *mosquitto__thread_main(void *obj);
28 |
29 | int mosquitto_loop_start(struct mosquitto *mosq)
30 | {
31 | #if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL)
32 | if(!mosq || mosq->threaded != mosq_ts_none) return MOSQ_ERR_INVAL;
33 |
34 | mosq->threaded = mosq_ts_self;
35 | if(!pthread_create(&mosq->thread_id, NULL, mosquitto__thread_main, mosq)){
36 | return MOSQ_ERR_SUCCESS;
37 | }else{
38 | return MOSQ_ERR_ERRNO;
39 | }
40 | #else
41 | return MOSQ_ERR_NOT_SUPPORTED;
42 | #endif
43 | }
44 |
45 | int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
46 | {
47 | #if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL)
48 | # ifndef WITH_BROKER
49 | char sockpair_data = 0;
50 | # endif
51 |
52 | if(!mosq || mosq->threaded != mosq_ts_self) return MOSQ_ERR_INVAL;
53 |
54 |
55 | /* Write a single byte to sockpairW (connected to sockpairR) to break out
56 | * of select() if in threaded mode. */
57 | if(mosq->sockpairW != INVALID_SOCKET){
58 | #ifndef WIN32
59 | if(write(mosq->sockpairW, &sockpair_data, 1)){
60 | }
61 | #else
62 | send(mosq->sockpairW, &sockpair_data, 1, 0);
63 | #endif
64 | }
65 |
66 | if(force){
67 | pthread_cancel(mosq->thread_id);
68 | }
69 | pthread_join(mosq->thread_id, NULL);
70 | mosq->thread_id = pthread_self();
71 | mosq->threaded = mosq_ts_none;
72 |
73 | return MOSQ_ERR_SUCCESS;
74 | #else
75 | return MOSQ_ERR_NOT_SUPPORTED;
76 | #endif
77 | }
78 |
79 | #ifdef WITH_THREADING
80 | void *mosquitto__thread_main(void *obj)
81 | {
82 | struct mosquitto *mosq = obj;
83 | int state;
84 | #ifndef WIN32
85 | struct timespec ts;
86 | ts.tv_sec = 0;
87 | ts.tv_nsec = 10000000;
88 | #endif
89 |
90 | if(!mosq) return NULL;
91 |
92 | do{
93 | state = mosquitto__get_state(mosq);
94 | if(state == mosq_cs_new){
95 | #ifdef WIN32
96 | Sleep(10);
97 | #else
98 | nanosleep(&ts, NULL);
99 | #endif
100 | }else{
101 | break;
102 | }
103 | }while(1);
104 |
105 | if(!mosq->keepalive){
106 | /* Sleep for a day if keepalive disabled. */
107 | mosquitto_loop_forever(mosq, 1000*86400, 1);
108 | }else{
109 | /* Sleep for our keepalive value. publish() etc. will wake us up. */
110 | mosquitto_loop_forever(mosq, mosq->keepalive*1000, 1);
111 | }
112 |
113 | return obj;
114 | }
115 | #endif
116 |
117 | int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded)
118 | {
119 | if(!mosq) return MOSQ_ERR_INVAL;
120 |
121 | if(threaded){
122 | mosq->threaded = mosq_ts_external;
123 | }else{
124 | mosq->threaded = mosq_ts_none;
125 | }
126 |
127 | return MOSQ_ERR_SUCCESS;
128 | }
129 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/utf8_mosq.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016-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.
15 | */
16 |
17 | #include "config.h"
18 |
19 | #include
20 | #include "mosquitto.h"
21 |
22 | int mosquitto_validate_utf8(const char *str, int len)
23 | {
24 | int i;
25 | int j;
26 | int codelen;
27 | int codepoint;
28 | const unsigned char *ustr = (const unsigned char *)str;
29 |
30 | if(!str) return MOSQ_ERR_INVAL;
31 | if(len < 0 || len > 65536) return MOSQ_ERR_INVAL;
32 |
33 | for(i=0; i 0xF4){
54 | /* Invalid, this would produce values > 0x10FFFF. */
55 | return MOSQ_ERR_MALFORMED_UTF8;
56 | }
57 | codelen = 4;
58 | codepoint = (ustr[i] & 0x07);
59 | }else{
60 | /* Unexpected continuation byte. */
61 | return MOSQ_ERR_MALFORMED_UTF8;
62 | }
63 |
64 | /* Reconstruct full code point */
65 | if(i == len-codelen+1){
66 | /* Not enough data */
67 | return MOSQ_ERR_MALFORMED_UTF8;
68 | }
69 | for(j=0; j= 0xD800 && codepoint <= 0xDFFF){
79 | return MOSQ_ERR_MALFORMED_UTF8;
80 | }
81 |
82 | /* Check for overlong or out of range encodings */
83 | /* Checking codelen == 2 isn't necessary here, because it is already
84 | * covered above in the C0 and C1 checks.
85 | * if(codelen == 2 && codepoint < 0x0080){
86 | * return MOSQ_ERR_MALFORMED_UTF8;
87 | * }else
88 | */
89 | if(codelen == 3 && codepoint < 0x0800){
90 | return MOSQ_ERR_MALFORMED_UTF8;
91 | }else if(codelen == 4 && (codepoint < 0x10000 || codepoint > 0x10FFFF)){
92 | return MOSQ_ERR_MALFORMED_UTF8;
93 | }
94 |
95 | /* Check for non-characters */
96 | if(codepoint >= 0xFDD0 && codepoint <= 0xFDEF){
97 | return MOSQ_ERR_MALFORMED_UTF8;
98 | }
99 | if((codepoint & 0xFFFF) == 0xFFFE || (codepoint & 0xFFFF) == 0xFFFF){
100 | return MOSQ_ERR_MALFORMED_UTF8;
101 | }
102 | /* Check for control characters */
103 | if(codepoint <= 0x001F || (codepoint >= 0x007F && codepoint <= 0x009F)){
104 | return MOSQ_ERR_MALFORMED_UTF8;
105 | }
106 | }
107 | return MOSQ_ERR_SUCCESS;
108 | }
109 |
110 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/cmac.h:
--------------------------------------------------------------------------------
1 | /* crypto/cmac/cmac.h */
2 | /*
3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4 | * project.
5 | */
6 | /* ====================================================================
7 | * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted provided that the following conditions
11 | * are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in
18 | * the documentation and/or other materials provided with the
19 | * distribution.
20 | *
21 | * 3. All advertising materials mentioning features or use of this
22 | * software must display the following acknowledgment:
23 | * "This product includes software developed by the OpenSSL Project
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 | *
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 | * endorse or promote products derived from this software without
28 | * prior written permission. For written permission, please contact
29 | * licensing@OpenSSL.org.
30 | *
31 | * 5. Products derived from this software may not be called "OpenSSL"
32 | * nor may "OpenSSL" appear in their names without prior written
33 | * permission of the OpenSSL Project.
34 | *
35 | * 6. Redistributions of any form whatsoever must retain the following
36 | * acknowledgment:
37 | * "This product includes software developed by the OpenSSL Project
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 | *
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 | * OF THE POSSIBILITY OF SUCH DAMAGE.
52 | * ====================================================================
53 | */
54 |
55 | #ifndef HEADER_CMAC_H
56 | # define HEADER_CMAC_H
57 |
58 | #ifdef __cplusplus
59 | extern "C" {
60 | #endif
61 |
62 | # include
63 |
64 | /* Opaque */
65 | typedef struct CMAC_CTX_st CMAC_CTX;
66 |
67 | CMAC_CTX *CMAC_CTX_new(void);
68 | void CMAC_CTX_cleanup(CMAC_CTX *ctx);
69 | void CMAC_CTX_free(CMAC_CTX *ctx);
70 | EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx);
71 | int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in);
72 |
73 | int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
74 | const EVP_CIPHER *cipher, ENGINE *impl);
75 | int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen);
76 | int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen);
77 | int CMAC_resume(CMAC_CTX *ctx);
78 |
79 | #ifdef __cplusplus
80 | }
81 | #endif
82 | #endif
83 |
--------------------------------------------------------------------------------
/library/src/main/jni/uthash/src/utstack.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2018-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 |
11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
12 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
13 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
15 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 | */
23 |
24 | #ifndef UTSTACK_H
25 | #define UTSTACK_H
26 |
27 | #define UTSTACK_VERSION 2.1.0
28 |
29 | /*
30 | * This file contains macros to manipulate a singly-linked list as a stack.
31 | *
32 | * To use utstack, your structure must have a "next" pointer.
33 | *
34 | * ----------------.EXAMPLE -------------------------
35 | * struct item {
36 | * int id;
37 | * struct item *next;
38 | * }
39 | *
40 | * struct item *stack = NULL:
41 | *
42 | * int main() {
43 | * int count;
44 | * struct item *tmp;
45 | * struct item *item = malloc(sizeof *item);
46 | * item->id = 42;
47 | * STACK_COUNT(stack, tmp, count); assert(count == 0);
48 | * STACK_PUSH(stack, item);
49 | * STACK_COUNT(stack, tmp, count); assert(count == 1);
50 | * STACK_POP(stack, item);
51 | * free(item);
52 | * STACK_COUNT(stack, tmp, count); assert(count == 0);
53 | * }
54 | * --------------------------------------------------
55 | */
56 |
57 | #define STACK_TOP(head) (head)
58 |
59 | #define STACK_EMPTY(head) (!(head))
60 |
61 | #define STACK_PUSH(head,add) \
62 | STACK_PUSH2(head,add,next)
63 |
64 | #define STACK_PUSH2(head,add,next) \
65 | do { \
66 | (add)->next = (head); \
67 | (head) = (add); \
68 | } while (0)
69 |
70 | #define STACK_POP(head,result) \
71 | STACK_POP2(head,result,next)
72 |
73 | #define STACK_POP2(head,result,next) \
74 | do { \
75 | (result) = (head); \
76 | (head) = (head)->next; \
77 | } while (0)
78 |
79 | #define STACK_COUNT(head,el,counter) \
80 | STACK_COUNT2(head,el,counter,next) \
81 |
82 | #define STACK_COUNT2(head,el,counter,next) \
83 | do { \
84 | (counter) = 0; \
85 | for ((el) = (head); el; (el) = (el)->next) { ++(counter); } \
86 | } while (0)
87 |
88 | #endif /* UTSTACK_H */
89 |
--------------------------------------------------------------------------------
/library/src/main/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | # ssl lib
4 | include $(CLEAR_VARS)
5 | LOCAL_MODULE := ssl
6 | LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libssl.a
7 | include $(PREBUILT_STATIC_LIBRARY)
8 |
9 | # crypto lib
10 | include $(CLEAR_VARS)
11 | LOCAL_MODULE := ssl_crypto
12 | LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libcrypto.a
13 | include $(PREBUILT_STATIC_LIBRARY)
14 |
15 | # build flag
16 | include $(CLEAR_VARS)
17 | LOCAL_CFLAGS += -fexceptions
18 | LOCAL_CPPFLAGS += -std=c++11
19 | LOCAL_LDLIBS += -llog -landroid
20 |
21 | # include
22 | LOCAL_C_INCLUDES += $(LOCAL_PATH)
23 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/openssl/include
24 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/uthash/src
25 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/mosquitto
26 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/mosquitto/lib
27 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/mosquitto/lib/cpp
28 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
29 |
30 | # mosquitto lib
31 | LOCAL_CFLAGS += -DWITH_SOCKS
32 | LOCAL_CFLAGS += -DWITH_EC
33 | LOCAL_CFLAGS += -DWITH_UUID
34 | LOCAL_CFLAGS += -DWITH_SYS_TREE
35 | LOCAL_CFLAGS += -DWITH_MENORY_TRACKING
36 | LOCAL_CFLAGS += -DWITH_PERSISTENCE
37 | LOCAL_CFLAGS += -DWITH_BRIDGE
38 | LOCAL_CFLAGS += -DWITH_THREADING
39 | LOCAL_CFLAGS += -DWITH_TLS_PSK
40 | LOCAL_CFLAGS += -DWITH_TLS
41 |
42 | LOCAL_SRC_FILES += mosquitto/lib/actions.c
43 | LOCAL_SRC_FILES += mosquitto/lib/alias_mosq.c
44 | LOCAL_SRC_FILES += mosquitto/lib/callbacks.c
45 | LOCAL_SRC_FILES += mosquitto/lib/connect.c
46 | LOCAL_SRC_FILES += mosquitto/lib/handle_auth.c
47 | LOCAL_SRC_FILES += mosquitto/lib/handle_connack.c
48 | LOCAL_SRC_FILES += mosquitto/lib/handle_disconnect.c
49 | LOCAL_SRC_FILES += mosquitto/lib/handle_ping.c
50 | LOCAL_SRC_FILES += mosquitto/lib/handle_pubackcomp.c
51 | LOCAL_SRC_FILES += mosquitto/lib/handle_publish.c
52 | LOCAL_SRC_FILES += mosquitto/lib/handle_pubrec.c
53 | LOCAL_SRC_FILES += mosquitto/lib/handle_pubrel.c
54 | LOCAL_SRC_FILES += mosquitto/lib/handle_suback.c
55 | LOCAL_SRC_FILES += mosquitto/lib/handle_unsuback.c
56 | LOCAL_SRC_FILES += mosquitto/lib/helpers.c
57 | LOCAL_SRC_FILES += mosquitto/lib/logging_mosq.c
58 | LOCAL_SRC_FILES += mosquitto/lib/loop.c
59 | LOCAL_SRC_FILES += mosquitto/lib/memory_mosq.c
60 | LOCAL_SRC_FILES += mosquitto/lib/messages_mosq.c
61 | LOCAL_SRC_FILES += mosquitto/lib/mosquitto.c
62 | LOCAL_SRC_FILES += mosquitto/lib/net_mosq_ocsp.c
63 | LOCAL_SRC_FILES += mosquitto/lib/net_mosq.c
64 | LOCAL_SRC_FILES += mosquitto/lib/options.c
65 | LOCAL_SRC_FILES += mosquitto/lib/packet_datatypes.c
66 | LOCAL_SRC_FILES += mosquitto/lib/packet_mosq.c
67 | LOCAL_SRC_FILES += mosquitto/lib/property_mosq.c
68 | LOCAL_SRC_FILES += mosquitto/lib/read_handle.c
69 | LOCAL_SRC_FILES += mosquitto/lib/send_connect.c
70 | LOCAL_SRC_FILES += mosquitto/lib/send_disconnect.c
71 | LOCAL_SRC_FILES += mosquitto/lib/send_mosq.c
72 | LOCAL_SRC_FILES += mosquitto/lib/send_publish.c
73 | LOCAL_SRC_FILES += mosquitto/lib/send_subscribe.c
74 | LOCAL_SRC_FILES += mosquitto/lib/send_unsubscribe.c
75 | LOCAL_SRC_FILES += mosquitto/lib/socks_mosq.c
76 | LOCAL_SRC_FILES += mosquitto/lib/srv_mosq.c
77 | LOCAL_SRC_FILES += mosquitto/lib/thread_mosq.c
78 | LOCAL_SRC_FILES += mosquitto/lib/time_mosq.c
79 | LOCAL_SRC_FILES += mosquitto/lib/tls_mosq.c
80 | LOCAL_SRC_FILES += mosquitto/lib/utf8_mosq.c
81 | LOCAL_SRC_FILES += mosquitto/lib/util_mosq.c
82 | LOCAL_SRC_FILES += mosquitto/lib/util_topic.c
83 | LOCAL_SRC_FILES += mosquitto/lib/will_mosq.c
84 |
85 | LOCAL_SRC_FILES += mosquitto_wrapper.cpp
86 | LOCAL_SRC_FILES += JNIEnvHandler.cpp
87 | LOCAL_SRC_FILES += MqttClient.cpp
88 |
89 | # link lib
90 | LOCAL_STATIC_LIBRARIES := ssl ssl_crypto
91 |
92 | # module name
93 | LOCAL_MODULE := mqtt
94 |
95 | include $(BUILD_SHARED_LIBRARY)
96 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/handle_pubrec.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__pubrec(struct mosquitto_db *db, struct mosquitto *mosq)
39 | {
40 | uint8_t reason_code = 0;
41 | uint16_t mid;
42 | int rc;
43 | mosquitto_property *properties = NULL;
44 | int state;
45 |
46 | assert(mosq);
47 |
48 | state = mosquitto__get_state(mosq);
49 | if(state != mosq_cs_active){
50 | return MOSQ_ERR_PROTOCOL;
51 | }
52 |
53 | rc = packet__read_uint16(&mosq->in_packet, &mid);
54 | if(rc) return rc;
55 | if(mid == 0) return MOSQ_ERR_PROTOCOL;
56 |
57 | if(mosq->protocol == mosq_p_mqtt5 && mosq->in_packet.remaining_length > 2){
58 | rc = packet__read_byte(&mosq->in_packet, &reason_code);
59 | if(rc) return rc;
60 |
61 | if(mosq->in_packet.remaining_length > 3){
62 | rc = property__read_all(CMD_PUBREC, &mosq->in_packet, &properties);
63 | if(rc) return rc;
64 | /* Immediately free, we don't do anything with Reason String or User Property at the moment */
65 | mosquitto_property_free_all(&properties);
66 | }
67 | }
68 |
69 | #ifdef WITH_BROKER
70 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBREC from %s (Mid: %d)", mosq->id, mid);
71 |
72 | if(reason_code < 0x80){
73 | rc = db__message_update_outgoing(mosq, mid, mosq_ms_wait_for_pubcomp, 2);
74 | }else{
75 | return db__message_delete_outgoing(db, mosq, mid, mosq_ms_wait_for_pubrec, 2);
76 | }
77 | #else
78 | UNUSED(db);
79 |
80 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PUBREC (Mid: %d)", mosq->id, mid);
81 |
82 | if(reason_code < 0x80 || mosq->protocol != mosq_p_mqtt5){
83 | rc = message__out_update(mosq, mid, mosq_ms_wait_for_pubcomp, 2);
84 | }else{
85 | if(!message__delete(mosq, mid, mosq_md_out, 2)){
86 | /* Only inform the client the message has been sent once. */
87 | pthread_mutex_lock(&mosq->callback_mutex);
88 | if(mosq->on_publish_v5){
89 | mosq->in_callback = true;
90 | mosq->on_publish_v5(mosq, mosq->userdata, mid, reason_code, properties);
91 | mosq->in_callback = false;
92 | }
93 | pthread_mutex_unlock(&mosq->callback_mutex);
94 | }
95 | util__increment_send_quota(mosq);
96 | pthread_mutex_lock(&mosq->msgs_out.mutex);
97 | message__release_to_inflight(mosq, mosq_md_out);
98 | pthread_mutex_unlock(&mosq->msgs_out.mutex);
99 | return MOSQ_ERR_SUCCESS;
100 | }
101 | #endif
102 | if(rc == MOSQ_ERR_NOT_FOUND){
103 | log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received PUBREC from %s for an unknown packet identifier %d.", mosq->id, mid);
104 | }else if(rc != MOSQ_ERR_SUCCESS){
105 | return rc;
106 | }
107 | rc = send__pubrel(mosq, mid);
108 | if(rc) return rc;
109 |
110 | return MOSQ_ERR_SUCCESS;
111 | }
112 |
113 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/memory_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 |
22 | #include "memory_mosq.h"
23 |
24 | #ifdef REAL_WITH_MEMORY_TRACKING
25 | # if defined(__APPLE__)
26 | # include
27 | # define malloc_usable_size malloc_size
28 | # elif defined(__FreeBSD__)
29 | # include
30 | # else
31 | # include
32 | # endif
33 | #endif
34 |
35 | #ifdef REAL_WITH_MEMORY_TRACKING
36 | static unsigned long memcount = 0;
37 | static unsigned long max_memcount = 0;
38 | #endif
39 |
40 | #ifdef WITH_BROKER
41 | static size_t mem_limit = 0;
42 | void memory__set_limit(size_t lim)
43 | {
44 | mem_limit = lim;
45 | }
46 | #endif
47 |
48 | void *mosquitto__calloc(size_t nmemb, size_t size)
49 | {
50 | #ifdef REAL_WITH_MEMORY_TRACKING
51 | if(mem_limit && memcount + size > mem_limit){
52 | return NULL;
53 | }
54 | #endif
55 | void *mem = calloc(nmemb, size);
56 |
57 | #ifdef REAL_WITH_MEMORY_TRACKING
58 | if(mem){
59 | memcount += malloc_usable_size(mem);
60 | if(memcount > max_memcount){
61 | max_memcount = memcount;
62 | }
63 | }
64 | #endif
65 |
66 | return mem;
67 | }
68 |
69 | void mosquitto__free(void *mem)
70 | {
71 | #ifdef REAL_WITH_MEMORY_TRACKING
72 | if(!mem){
73 | return;
74 | }
75 | memcount -= malloc_usable_size(mem);
76 | #endif
77 | free(mem);
78 | }
79 |
80 | void *mosquitto__malloc(size_t size)
81 | {
82 | #ifdef REAL_WITH_MEMORY_TRACKING
83 | if(mem_limit && memcount + size > mem_limit){
84 | return NULL;
85 | }
86 | #endif
87 | void *mem = malloc(size);
88 |
89 | #ifdef REAL_WITH_MEMORY_TRACKING
90 | if(mem){
91 | memcount += malloc_usable_size(mem);
92 | if(memcount > max_memcount){
93 | max_memcount = memcount;
94 | }
95 | }
96 | #endif
97 |
98 | return mem;
99 | }
100 |
101 | #ifdef REAL_WITH_MEMORY_TRACKING
102 | unsigned long mosquitto__memory_used(void)
103 | {
104 | return memcount;
105 | }
106 |
107 | unsigned long mosquitto__max_memory_used(void)
108 | {
109 | return max_memcount;
110 | }
111 | #endif
112 |
113 | void *mosquitto__realloc(void *ptr, size_t size)
114 | {
115 | #ifdef REAL_WITH_MEMORY_TRACKING
116 | if(mem_limit && memcount + size > mem_limit){
117 | return NULL;
118 | }
119 | #endif
120 | void *mem;
121 | #ifdef REAL_WITH_MEMORY_TRACKING
122 | if(ptr){
123 | memcount -= malloc_usable_size(ptr);
124 | }
125 | #endif
126 | mem = realloc(ptr, size);
127 |
128 | #ifdef REAL_WITH_MEMORY_TRACKING
129 | if(mem){
130 | memcount += malloc_usable_size(mem);
131 | if(memcount > max_memcount){
132 | max_memcount = memcount;
133 | }
134 | }
135 | #endif
136 |
137 | return mem;
138 | }
139 |
140 | char *mosquitto__strdup(const char *s)
141 | {
142 | #ifdef REAL_WITH_MEMORY_TRACKING
143 | if(mem_limit && memcount + strlen(s) > mem_limit){
144 | return NULL;
145 | }
146 | #endif
147 | char *str = strdup(s);
148 |
149 | #ifdef REAL_WITH_MEMORY_TRACKING
150 | if(str){
151 | memcount += malloc_usable_size(str);
152 | if(memcount > max_memcount){
153 | max_memcount = memcount;
154 | }
155 | }
156 | #endif
157 |
158 | return str;
159 | }
160 |
161 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/ui_compat.h:
--------------------------------------------------------------------------------
1 | /* crypto/ui/ui.h */
2 | /*
3 | * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
4 | * 2001.
5 | */
6 | /* ====================================================================
7 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted provided that the following conditions
11 | * are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in
18 | * the documentation and/or other materials provided with the
19 | * distribution.
20 | *
21 | * 3. All advertising materials mentioning features or use of this
22 | * software must display the following acknowledgment:
23 | * "This product includes software developed by the OpenSSL Project
24 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 | *
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 | * endorse or promote products derived from this software without
28 | * prior written permission. For written permission, please contact
29 | * openssl-core@openssl.org.
30 | *
31 | * 5. Products derived from this software may not be called "OpenSSL"
32 | * nor may "OpenSSL" appear in their names without prior written
33 | * permission of the OpenSSL Project.
34 | *
35 | * 6. Redistributions of any form whatsoever must retain the following
36 | * acknowledgment:
37 | * "This product includes software developed by the OpenSSL Project
38 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 | *
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 | * OF THE POSSIBILITY OF SUCH DAMAGE.
52 | * ====================================================================
53 | *
54 | * This product includes cryptographic software written by Eric Young
55 | * (eay@cryptsoft.com). This product includes software written by Tim
56 | * Hudson (tjh@cryptsoft.com).
57 | *
58 | */
59 |
60 | #ifndef HEADER_UI_COMPAT_H
61 | # define HEADER_UI_COMPAT_H
62 |
63 | # include
64 | # include
65 |
66 | #ifdef __cplusplus
67 | extern "C" {
68 | #endif
69 |
70 | /*
71 | * The following functions were previously part of the DES section, and are
72 | * provided here for backward compatibility reasons.
73 | */
74 |
75 | # define des_read_pw_string(b,l,p,v) \
76 | _ossl_old_des_read_pw_string((b),(l),(p),(v))
77 | # define des_read_pw(b,bf,s,p,v) \
78 | _ossl_old_des_read_pw((b),(bf),(s),(p),(v))
79 |
80 | int _ossl_old_des_read_pw_string(char *buf, int length, const char *prompt,
81 | int verify);
82 | int _ossl_old_des_read_pw(char *buf, char *buff, int size, const char *prompt,
83 | int verify);
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 | #endif
89 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/will_mosq.c:
--------------------------------------------------------------------------------
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 | #include "config.h"
18 |
19 | #include
20 | #include
21 |
22 | #ifdef WITH_BROKER
23 | # include "mosquitto_broker_internal.h"
24 | #endif
25 |
26 | #include "mosquitto.h"
27 | #include "mosquitto_internal.h"
28 | #include "logging_mosq.h"
29 | #include "messages_mosq.h"
30 | #include "memory_mosq.h"
31 | #include "mqtt_protocol.h"
32 | #include "net_mosq.h"
33 | #include "read_handle.h"
34 | #include "send_mosq.h"
35 | #include "util_mosq.h"
36 | #include "will_mosq.h"
37 |
38 | int will__set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties)
39 | {
40 | int rc = MOSQ_ERR_SUCCESS;
41 | mosquitto_property *p;
42 |
43 | if(!mosq || !topic) return MOSQ_ERR_INVAL;
44 | if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
45 | if(payloadlen > 0 && !payload) return MOSQ_ERR_INVAL;
46 |
47 | if(mosquitto_pub_topic_check(topic)) return MOSQ_ERR_INVAL;
48 | if(mosquitto_validate_utf8(topic, strlen(topic))) return MOSQ_ERR_MALFORMED_UTF8;
49 |
50 | if(properties){
51 | if(mosq->protocol != mosq_p_mqtt5){
52 | return MOSQ_ERR_NOT_SUPPORTED;
53 | }
54 | p = properties;
55 | while(p){
56 | rc = mosquitto_property_check_command(CMD_WILL, p->identifier);
57 | if(rc) return rc;
58 | p = p->next;
59 | }
60 | }
61 |
62 | if(mosq->will){
63 | mosquitto__free(mosq->will->msg.topic);
64 | mosquitto__free(mosq->will->msg.payload);
65 | mosquitto_property_free_all(&mosq->will->properties);
66 | mosquitto__free(mosq->will);
67 | }
68 |
69 | mosq->will = mosquitto__calloc(1, sizeof(struct mosquitto_message_all));
70 | if(!mosq->will) return MOSQ_ERR_NOMEM;
71 | mosq->will->msg.topic = mosquitto__strdup(topic);
72 | if(!mosq->will->msg.topic){
73 | rc = MOSQ_ERR_NOMEM;
74 | goto cleanup;
75 | }
76 | mosq->will->msg.payloadlen = payloadlen;
77 | if(mosq->will->msg.payloadlen > 0){
78 | if(!payload){
79 | rc = MOSQ_ERR_INVAL;
80 | goto cleanup;
81 | }
82 | mosq->will->msg.payload = mosquitto__malloc(sizeof(char)*mosq->will->msg.payloadlen);
83 | if(!mosq->will->msg.payload){
84 | rc = MOSQ_ERR_NOMEM;
85 | goto cleanup;
86 | }
87 |
88 | memcpy(mosq->will->msg.payload, payload, payloadlen);
89 | }
90 | mosq->will->msg.qos = qos;
91 | mosq->will->msg.retain = retain;
92 |
93 | mosq->will->properties = properties;
94 |
95 | return MOSQ_ERR_SUCCESS;
96 |
97 | cleanup:
98 | if(mosq->will){
99 | mosquitto__free(mosq->will->msg.topic);
100 | mosquitto__free(mosq->will->msg.payload);
101 |
102 | mosquitto__free(mosq->will);
103 | mosq->will = NULL;
104 | }
105 |
106 | return rc;
107 | }
108 |
109 | int will__clear(struct mosquitto *mosq)
110 | {
111 | if(!mosq->will) return MOSQ_ERR_SUCCESS;
112 |
113 | mosquitto__free(mosq->will->msg.topic);
114 | mosq->will->msg.topic = NULL;
115 |
116 | mosquitto__free(mosq->will->msg.payload);
117 | mosq->will->msg.payload = NULL;
118 |
119 | mosquitto_property_free_all(&mosq->will->properties);
120 |
121 | mosquitto__free(mosq->will);
122 | mosq->will = NULL;
123 |
124 | return MOSQ_ERR_SUCCESS;
125 | }
126 |
127 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/handle_pubackcomp.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 |
39 | #ifdef WITH_BROKER
40 | int handle__pubackcomp(struct mosquitto_db *db, struct mosquitto *mosq, const char *type)
41 | #else
42 | int handle__pubackcomp(struct mosquitto *mosq, const char *type)
43 | #endif
44 | {
45 | uint8_t reason_code = 0;
46 | uint16_t mid;
47 | int rc;
48 | mosquitto_property *properties = NULL;
49 | int qos;
50 | int state;
51 |
52 | assert(mosq);
53 |
54 | state = mosquitto__get_state(mosq);
55 | if(state != mosq_cs_active){
56 | return MOSQ_ERR_PROTOCOL;
57 | }
58 |
59 | pthread_mutex_lock(&mosq->msgs_out.mutex);
60 | util__increment_send_quota(mosq);
61 | pthread_mutex_unlock(&mosq->msgs_out.mutex);
62 |
63 | rc = packet__read_uint16(&mosq->in_packet, &mid);
64 | if(rc) return rc;
65 | qos = type[3] == 'A'?1:2; /* pubAck or pubComp */
66 | if(mid == 0) return MOSQ_ERR_PROTOCOL;
67 |
68 | if(mosq->protocol == mosq_p_mqtt5 && mosq->in_packet.remaining_length > 2){
69 | rc = packet__read_byte(&mosq->in_packet, &reason_code);
70 | if(rc) return rc;
71 |
72 | if(mosq->in_packet.remaining_length > 3){
73 | rc = property__read_all(CMD_PUBACK, &mosq->in_packet, &properties);
74 | if(rc) return rc;
75 | }
76 | }
77 |
78 | #ifdef WITH_BROKER
79 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received %s from %s (Mid: %d, RC:%d)", type, mosq->id, mid, reason_code);
80 |
81 | /* Immediately free, we don't do anything with Reason String or User Property at the moment */
82 | mosquitto_property_free_all(&properties);
83 |
84 | rc = db__message_delete_outgoing(db, mosq, mid, mosq_ms_wait_for_pubcomp, qos);
85 | if(rc == MOSQ_ERR_NOT_FOUND){
86 | log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received %s from %s for an unknown packet identifier %d.", type, mosq->id, mid);
87 | return MOSQ_ERR_SUCCESS;
88 | }else{
89 | return rc;
90 | }
91 | #else
92 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received %s (Mid: %d, RC:%d)", mosq->id, type, mid, reason_code);
93 |
94 | rc = message__delete(mosq, mid, mosq_md_out, qos);
95 | if(rc){
96 | return rc;
97 | }else{
98 | /* Only inform the client the message has been sent once. */
99 | pthread_mutex_lock(&mosq->callback_mutex);
100 | if(mosq->on_publish){
101 | mosq->in_callback = true;
102 | mosq->on_publish(mosq, mosq->userdata, mid);
103 | mosq->in_callback = false;
104 | }
105 | if(mosq->on_publish_v5){
106 | mosq->in_callback = true;
107 | mosq->on_publish_v5(mosq, mosq->userdata, mid, reason_code, properties);
108 | mosq->in_callback = false;
109 | }
110 | pthread_mutex_unlock(&mosq->callback_mutex);
111 | mosquitto_property_free_all(&properties);
112 | }
113 | pthread_mutex_lock(&mosq->msgs_out.mutex);
114 | message__release_to_inflight(mosq, mosq_md_out);
115 | pthread_mutex_unlock(&mosq->msgs_out.mutex);
116 |
117 | return MOSQ_ERR_SUCCESS;
118 | #endif
119 | }
120 |
121 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/handle_pubrel.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 |
39 | int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
40 | {
41 | uint8_t reason_code;
42 | uint16_t mid;
43 | #ifndef WITH_BROKER
44 | struct mosquitto_message_all *message = NULL;
45 | #endif
46 | int rc;
47 | mosquitto_property *properties = NULL;
48 | int state;
49 |
50 | assert(mosq);
51 |
52 | state = mosquitto__get_state(mosq);
53 | if(state != mosq_cs_active){
54 | return MOSQ_ERR_PROTOCOL;
55 | }
56 |
57 | if(mosq->protocol != mosq_p_mqtt31){
58 | if((mosq->in_packet.command&0x0F) != 0x02){
59 | return MOSQ_ERR_PROTOCOL;
60 | }
61 | }
62 | rc = packet__read_uint16(&mosq->in_packet, &mid);
63 | if(rc) return rc;
64 | if(mid == 0) return MOSQ_ERR_PROTOCOL;
65 |
66 | if(mosq->protocol == mosq_p_mqtt5 && mosq->in_packet.remaining_length > 2){
67 | rc = packet__read_byte(&mosq->in_packet, &reason_code);
68 | if(rc) return rc;
69 |
70 | if(mosq->in_packet.remaining_length > 3){
71 | rc = property__read_all(CMD_PUBREL, &mosq->in_packet, &properties);
72 | if(rc) return rc;
73 | }
74 | }
75 |
76 | #ifdef WITH_BROKER
77 | log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBREL from %s (Mid: %d)", mosq->id, mid);
78 |
79 | /* Immediately free, we don't do anything with Reason String or User Property at the moment */
80 | mosquitto_property_free_all(&properties);
81 |
82 | rc = db__message_release_incoming(db, mosq, mid);
83 | if(rc == MOSQ_ERR_NOT_FOUND){
84 | /* Message not found. Still send a PUBCOMP anyway because this could be
85 | * due to a repeated PUBREL after a client has reconnected. */
86 | }else if(rc != MOSQ_ERR_SUCCESS){
87 | return rc;
88 | }
89 |
90 | rc = send__pubcomp(mosq, mid);
91 | if(rc) return rc;
92 | #else
93 | UNUSED(db);
94 |
95 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PUBREL (Mid: %d)", mosq->id, mid);
96 |
97 | rc = send__pubcomp(mosq, mid);
98 | if(rc){
99 | message__remove(mosq, mid, mosq_md_in, &message, 2);
100 | return rc;
101 | }
102 |
103 | rc = message__remove(mosq, mid, mosq_md_in, &message, 2);
104 | if(rc){
105 | return rc;
106 | }else{
107 | /* Only pass the message on if we have removed it from the queue - this
108 | * prevents multiple callbacks for the same message. */
109 | pthread_mutex_lock(&mosq->callback_mutex);
110 | if(mosq->on_message){
111 | mosq->in_callback = true;
112 | mosq->on_message(mosq, mosq->userdata, &message->msg);
113 | mosq->in_callback = false;
114 | }
115 | if(mosq->on_message_v5){
116 | mosq->in_callback = true;
117 | mosq->on_message_v5(mosq, mosq->userdata, &message->msg, message->properties);
118 | mosq->in_callback = false;
119 | }
120 | pthread_mutex_unlock(&mosq->callback_mutex);
121 | mosquitto_property_free_all(&properties);
122 | message__cleanup(&message);
123 | }
124 | #endif
125 |
126 | return MOSQ_ERR_SUCCESS;
127 | }
128 |
129 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/ssl23.h:
--------------------------------------------------------------------------------
1 | /* ssl/ssl23.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_SSL23_H
60 | # define HEADER_SSL23_H
61 |
62 | #ifdef __cplusplus
63 | extern "C" {
64 | #endif
65 |
66 | /*
67 | * client
68 | */
69 | /* write to server */
70 | # define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT)
71 | # define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT)
72 | /* read from server */
73 | # define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT)
74 | # define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT)
75 |
76 | /* server */
77 | /* read from client */
78 | # define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT)
79 | # define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT)
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 | #endif
85 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/rc4.h:
--------------------------------------------------------------------------------
1 | /* crypto/rc4/rc4.h */
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_RC4_H
60 | # define HEADER_RC4_H
61 |
62 | # include /* OPENSSL_NO_RC4, RC4_INT */
63 | # ifdef OPENSSL_NO_RC4
64 | # error RC4 is disabled.
65 | # endif
66 |
67 | # include
68 |
69 | #ifdef __cplusplus
70 | extern "C" {
71 | #endif
72 |
73 | typedef struct rc4_key_st {
74 | RC4_INT x, y;
75 | RC4_INT data[256];
76 | } RC4_KEY;
77 |
78 | const char *RC4_options(void);
79 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
80 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
81 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
82 | unsigned char *outdata);
83 |
84 | #ifdef __cplusplus
85 | }
86 | #endif
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/pqueue.h:
--------------------------------------------------------------------------------
1 | /* crypto/pqueue/pqueue.h */
2 | /*
3 | * DTLS implementation written by Nagendra Modadugu
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 | */
6 | /* ====================================================================
7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted provided that the following conditions
11 | * are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | *
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in
18 | * the documentation and/or other materials provided with the
19 | * distribution.
20 | *
21 | * 3. All advertising materials mentioning features or use of this
22 | * software must display the following acknowledgment:
23 | * "This product includes software developed by the OpenSSL Project
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 | *
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 | * endorse or promote products derived from this software without
28 | * prior written permission. For written permission, please contact
29 | * openssl-core@OpenSSL.org.
30 | *
31 | * 5. Products derived from this software may not be called "OpenSSL"
32 | * nor may "OpenSSL" appear in their names without prior written
33 | * permission of the OpenSSL Project.
34 | *
35 | * 6. Redistributions of any form whatsoever must retain the following
36 | * acknowledgment:
37 | * "This product includes software developed by the OpenSSL Project
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 | *
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 | * OF THE POSSIBILITY OF SUCH DAMAGE.
52 | * ====================================================================
53 | *
54 | * This product includes cryptographic software written by Eric Young
55 | * (eay@cryptsoft.com). This product includes software written by Tim
56 | * Hudson (tjh@cryptsoft.com).
57 | *
58 | */
59 |
60 | #ifndef HEADER_PQUEUE_H
61 | # define HEADER_PQUEUE_H
62 |
63 | # include
64 | # include
65 | # include
66 |
67 | #ifdef __cplusplus
68 | extern "C" {
69 | #endif
70 | typedef struct _pqueue *pqueue;
71 |
72 | typedef struct _pitem {
73 | unsigned char priority[8]; /* 64-bit value in big-endian encoding */
74 | void *data;
75 | struct _pitem *next;
76 | } pitem;
77 |
78 | typedef struct _pitem *piterator;
79 |
80 | pitem *pitem_new(unsigned char *prio64be, void *data);
81 | void pitem_free(pitem *item);
82 |
83 | pqueue pqueue_new(void);
84 | void pqueue_free(pqueue pq);
85 |
86 | pitem *pqueue_insert(pqueue pq, pitem *item);
87 | pitem *pqueue_peek(pqueue pq);
88 | pitem *pqueue_pop(pqueue pq);
89 | pitem *pqueue_find(pqueue pq, unsigned char *prio64be);
90 | pitem *pqueue_iterator(pqueue pq);
91 | pitem *pqueue_next(piterator *iter);
92 |
93 | void pqueue_print(pqueue pq);
94 | int pqueue_size(pqueue pq);
95 |
96 | #ifdef __cplusplus
97 | }
98 | #endif
99 | #endif /* ! HEADER_PQUEUE_H */
100 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/mdc2.h:
--------------------------------------------------------------------------------
1 | /* crypto/mdc2/mdc2.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_MDC2_H
60 | # define HEADER_MDC2_H
61 |
62 | # include
63 |
64 | #ifdef __cplusplus
65 | extern "C" {
66 | #endif
67 |
68 | # ifdef OPENSSL_NO_MDC2
69 | # error MDC2 is disabled.
70 | # endif
71 |
72 | # define MDC2_BLOCK 8
73 | # define MDC2_DIGEST_LENGTH 16
74 |
75 | typedef struct mdc2_ctx_st {
76 | unsigned int num;
77 | unsigned char data[MDC2_BLOCK];
78 | DES_cblock h, hh;
79 | int pad_type; /* either 1 or 2, default 1 */
80 | } MDC2_CTX;
81 |
82 | # ifdef OPENSSL_FIPS
83 | int private_MDC2_Init(MDC2_CTX *c);
84 | # endif
85 | int MDC2_Init(MDC2_CTX *c);
86 | int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len);
87 | int MDC2_Final(unsigned char *md, MDC2_CTX *c);
88 | unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md);
89 |
90 | #ifdef __cplusplus
91 | }
92 | #endif
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/key/yao/mqtt/client/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package moe.key.yao.mqtt.client
2 |
3 | import android.Manifest
4 | import android.content.pm.PackageManager
5 | import android.os.Bundle
6 | import android.widget.Toast
7 | import androidx.appcompat.app.AppCompatActivity
8 | import androidx.core.app.ActivityCompat
9 | import androidx.core.content.ContextCompat
10 | import com.google.common.io.ByteStreams
11 | import kotlinx.android.synthetic.main.activity_main.*
12 | import moe.key.yao.mqtt.library.MqttClient
13 | import java.io.File
14 | import java.io.FileOutputStream
15 |
16 | class MainActivity : AppCompatActivity(), MqttClient.MqttCallback {
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | setContentView(R.layout.activity_main)
21 | MqttClient.getInstance().setOnMqttCallback(this)
22 | initLayout()
23 | initPermission()
24 | }
25 |
26 | override fun onDestroy() {
27 | super.onDestroy()
28 | MqttClient.getInstance().setOnMqttCallback(null)
29 | }
30 |
31 | private fun initLayout() {
32 | btn_start.setOnClickListener {
33 | startMqttService()
34 | }
35 | btn_subscribe.setOnClickListener {
36 | subscribeTopic()
37 | }
38 | btn_unsubscribe.setOnClickListener {
39 | unsubscribeTopic()
40 | }
41 | btn_publish.setOnClickListener {
42 | publishMessage()
43 | }
44 | }
45 |
46 | private fun initPermission() {
47 | val hasPermission: Int = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
48 | if (hasPermission != PackageManager.PERMISSION_GRANTED) {
49 | ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
50 | return
51 | }
52 | }
53 |
54 | private fun startMqttService() {
55 | // copy ca file to sdcard
56 | /*val caFilePath = "${getExternalFilesDir(null)}/ca.crt"
57 | val file = File(caFilePath)
58 | if (!file.exists()) {
59 | file.createNewFile()
60 | val inStream = assets.open("ca.crt")
61 | val outStream = FileOutputStream(file)
62 | ByteStreams.copy(inStream, outStream)
63 | inStream.close()
64 | outStream.close()
65 | }*/
66 |
67 | MqttClient.getInstance().start("192.168.1.101", 1883, "mqtt_android_client", false)
68 | //MqttClient.getInstance().start("192.168.1.101", 8883, "mqtt_android_client", false, caFilePath, "username", "password")
69 | }
70 |
71 | private fun subscribeTopic() {
72 | val topic = "/android/test/topicA"
73 | MqttClient.getInstance().subscribe(topic)
74 | }
75 |
76 | private fun unsubscribeTopic() {
77 | val topic = "/android/test/topicA"
78 | MqttClient.getInstance().unsubscribe(topic)
79 | }
80 |
81 | private fun publishMessage() {
82 | val topic = "/android/test/topicA"
83 | val message = "test message"
84 | MqttClient.getInstance().publish(topic, message)
85 | }
86 |
87 | override fun onMessage(topic: String, message: String) {
88 | println("on message: $topic | $message")
89 | }
90 |
91 | override fun onLog(str: String?) {
92 | println("on log: $str")
93 | }
94 |
95 | override fun onRequestPermissionsResult(
96 | requestCode: Int,
97 | permissions: Array,
98 | grantResults: IntArray
99 | ) {
100 | super.onRequestPermissionsResult(requestCode, permissions, grantResults)
101 | if (requestCode == 1) {
102 | var flag = false
103 | for (i in permissions.indices) {
104 | if (permissions[i] == Manifest.permission.READ_EXTERNAL_STORAGE && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
105 | flag = true
106 | break
107 | }
108 | }
109 | if (!flag) {
110 | Toast.makeText(this, "获取权限失败", Toast.LENGTH_SHORT).show()
111 | }
112 | }
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/opensslv.h:
--------------------------------------------------------------------------------
1 | #ifndef HEADER_OPENSSLV_H
2 | # define HEADER_OPENSSLV_H
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | /*-
9 | * Numeric release version identifier:
10 | * MNNFFPPS: major minor fix patch status
11 | * The status nibble has one of the values 0 for development, 1 to e for betas
12 | * 1 to 14, and f for release. The patch level is exactly that.
13 | * For example:
14 | * 0.9.3-dev 0x00903000
15 | * 0.9.3-beta1 0x00903001
16 | * 0.9.3-beta2-dev 0x00903002
17 | * 0.9.3-beta2 0x00903002 (same as ...beta2-dev)
18 | * 0.9.3 0x0090300f
19 | * 0.9.3a 0x0090301f
20 | * 0.9.4 0x0090400f
21 | * 1.2.3z 0x102031af
22 | *
23 | * For continuity reasons (because 0.9.5 is already out, and is coded
24 | * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level
25 | * part is slightly different, by setting the highest bit. This means
26 | * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start
27 | * with 0x0090600S...
28 | *
29 | * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
30 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
31 | * major minor fix final patch/beta)
32 | */
33 | # define OPENSSL_VERSION_NUMBER 0x100020bfL
34 | # ifdef OPENSSL_FIPS
35 | # define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2k-fips 26 Jan 2017"
36 | # else
37 | # define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2k 26 Jan 2017"
38 | # endif
39 | # define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
40 |
41 | /*-
42 | * The macros below are to be used for shared library (.so, .dll, ...)
43 | * versioning. That kind of versioning works a bit differently between
44 | * operating systems. The most usual scheme is to set a major and a minor
45 | * number, and have the runtime loader check that the major number is equal
46 | * to what it was at application link time, while the minor number has to
47 | * be greater or equal to what it was at application link time. With this
48 | * scheme, the version number is usually part of the file name, like this:
49 | *
50 | * libcrypto.so.0.9
51 | *
52 | * Some unixen also make a softlink with the major verson number only:
53 | *
54 | * libcrypto.so.0
55 | *
56 | * On Tru64 and IRIX 6.x it works a little bit differently. There, the
57 | * shared library version is stored in the file, and is actually a series
58 | * of versions, separated by colons. The rightmost version present in the
59 | * library when linking an application is stored in the application to be
60 | * matched at run time. When the application is run, a check is done to
61 | * see if the library version stored in the application matches any of the
62 | * versions in the version string of the library itself.
63 | * This version string can be constructed in any way, depending on what
64 | * kind of matching is desired. However, to implement the same scheme as
65 | * the one used in the other unixen, all compatible versions, from lowest
66 | * to highest, should be part of the string. Consecutive builds would
67 | * give the following versions strings:
68 | *
69 | * 3.0
70 | * 3.0:3.1
71 | * 3.0:3.1:3.2
72 | * 4.0
73 | * 4.0:4.1
74 | *
75 | * Notice how version 4 is completely incompatible with version, and
76 | * therefore give the breach you can see.
77 | *
78 | * There may be other schemes as well that I haven't yet discovered.
79 | *
80 | * So, here's the way it works here: first of all, the library version
81 | * number doesn't need at all to match the overall OpenSSL version.
82 | * However, it's nice and more understandable if it actually does.
83 | * The current library version is stored in the macro SHLIB_VERSION_NUMBER,
84 | * which is just a piece of text in the format "M.m.e" (Major, minor, edit).
85 | * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways,
86 | * we need to keep a history of version numbers, which is done in the
87 | * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and
88 | * should only keep the versions that are binary compatible with the current.
89 | */
90 | # define SHLIB_VERSION_HISTORY ""
91 | # define SHLIB_VERSION_NUMBER "1.0.0"
92 |
93 |
94 | #ifdef __cplusplus
95 | }
96 | #endif
97 | #endif /* HEADER_OPENSSLV_H */
98 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/conf_api.h:
--------------------------------------------------------------------------------
1 | /* conf_api.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_CONF_API_H
60 | # define HEADER_CONF_API_H
61 |
62 | # include
63 | # include
64 |
65 | #ifdef __cplusplus
66 | extern "C" {
67 | #endif
68 |
69 | /* Up until OpenSSL 0.9.5a, this was new_section */
70 | CONF_VALUE *_CONF_new_section(CONF *conf, const char *section);
71 | /* Up until OpenSSL 0.9.5a, this was get_section */
72 | CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section);
73 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */
74 | STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
75 | const char *section);
76 |
77 | int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
78 | char *_CONF_get_string(const CONF *conf, const char *section,
79 | const char *name);
80 | long _CONF_get_number(const CONF *conf, const char *section,
81 | const char *name);
82 |
83 | int _CONF_new_data(CONF *conf);
84 | void _CONF_free_data(CONF *conf);
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 | #endif
90 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/handle_connack.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 |
21 | #include "mosquitto.h"
22 | #include "logging_mosq.h"
23 | #include "memory_mosq.h"
24 | #include "messages_mosq.h"
25 | #include "mqtt_protocol.h"
26 | #include "net_mosq.h"
27 | #include "packet_mosq.h"
28 | #include "property_mosq.h"
29 | #include "read_handle.h"
30 |
31 | static void connack_callback(struct mosquitto *mosq, uint8_t reason_code, uint8_t connect_flags, const mosquitto_property *properties)
32 | {
33 | log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK (%d)", mosq->id, reason_code);
34 | if(reason_code == MQTT_RC_SUCCESS){
35 | mosq->reconnects = 0;
36 | }
37 | pthread_mutex_lock(&mosq->callback_mutex);
38 | if(mosq->on_connect){
39 | mosq->in_callback = true;
40 | mosq->on_connect(mosq, mosq->userdata, reason_code);
41 | mosq->in_callback = false;
42 | }
43 | if(mosq->on_connect_with_flags){
44 | mosq->in_callback = true;
45 | mosq->on_connect_with_flags(mosq, mosq->userdata, reason_code, connect_flags);
46 | mosq->in_callback = false;
47 | }
48 | if(mosq->on_connect_v5){
49 | mosq->in_callback = true;
50 | mosq->on_connect_v5(mosq, mosq->userdata, reason_code, connect_flags, properties);
51 | mosq->in_callback = false;
52 | }
53 | pthread_mutex_unlock(&mosq->callback_mutex);
54 | }
55 |
56 |
57 | int handle__connack(struct mosquitto *mosq)
58 | {
59 | uint8_t connect_flags;
60 | uint8_t reason_code;
61 | int rc;
62 | mosquitto_property *properties = NULL;
63 | char *clientid = NULL;
64 |
65 | assert(mosq);
66 | rc = packet__read_byte(&mosq->in_packet, &connect_flags);
67 | if(rc) return rc;
68 | rc = packet__read_byte(&mosq->in_packet, &reason_code);
69 | if(rc) return rc;
70 |
71 | if(mosq->protocol == mosq_p_mqtt5){
72 | rc = property__read_all(CMD_CONNACK, &mosq->in_packet, &properties);
73 |
74 | if(rc == MOSQ_ERR_PROTOCOL && reason_code == CONNACK_REFUSED_PROTOCOL_VERSION){
75 | /* This could occur because we are connecting to a v3.x broker and
76 | * it has replied with "unacceptable protocol version", but with a
77 | * v3 CONNACK. */
78 |
79 | connack_callback(mosq, MQTT_RC_UNSUPPORTED_PROTOCOL_VERSION, connect_flags, NULL);
80 | return rc;
81 | }else if(rc){
82 | return rc;
83 | }
84 | }
85 |
86 | mosquitto_property_read_string(properties, MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER, &clientid, false);
87 | if(clientid){
88 | if(mosq->id){
89 | /* We've been sent a client identifier but already have one. This
90 | * shouldn't happen. */
91 | free(clientid);
92 | mosquitto_property_free_all(&properties);
93 | return MOSQ_ERR_PROTOCOL;
94 | }else{
95 | mosq->id = clientid;
96 | clientid = NULL;
97 | }
98 | }
99 |
100 | mosquitto_property_read_byte(properties, MQTT_PROP_MAXIMUM_QOS, &mosq->maximum_qos, false);
101 | mosquitto_property_read_int16(properties, MQTT_PROP_RECEIVE_MAXIMUM, &mosq->msgs_out.inflight_maximum, false);
102 | mosquitto_property_read_int16(properties, MQTT_PROP_SERVER_KEEP_ALIVE, &mosq->keepalive, false);
103 | mosquitto_property_read_int32(properties, MQTT_PROP_MAXIMUM_PACKET_SIZE, &mosq->maximum_packet_size, false);
104 |
105 | mosq->msgs_out.inflight_quota = mosq->msgs_out.inflight_maximum;
106 |
107 | connack_callback(mosq, reason_code, connect_flags, properties);
108 | mosquitto_property_free_all(&properties);
109 |
110 | switch(reason_code){
111 | case 0:
112 | pthread_mutex_lock(&mosq->state_mutex);
113 | if(mosq->state != mosq_cs_disconnecting){
114 | mosq->state = mosq_cs_active;
115 | }
116 | pthread_mutex_unlock(&mosq->state_mutex);
117 | message__retry_check(mosq);
118 | return MOSQ_ERR_SUCCESS;
119 | case 1:
120 | case 2:
121 | case 3:
122 | case 4:
123 | case 5:
124 | return MOSQ_ERR_CONN_REFUSED;
125 | default:
126 | return MOSQ_ERR_PROTOCOL;
127 | }
128 | }
129 |
130 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/ripemd.h:
--------------------------------------------------------------------------------
1 | /* crypto/ripemd/ripemd.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_RIPEMD_H
60 | # define HEADER_RIPEMD_H
61 |
62 | # include
63 | # include
64 |
65 | #ifdef __cplusplus
66 | extern "C" {
67 | #endif
68 |
69 | # ifdef OPENSSL_NO_RIPEMD
70 | # error RIPEMD is disabled.
71 | # endif
72 |
73 | # if defined(__LP32__)
74 | # define RIPEMD160_LONG unsigned long
75 | # elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
76 | # define RIPEMD160_LONG unsigned long
77 | # define RIPEMD160_LONG_LOG2 3
78 | # else
79 | # define RIPEMD160_LONG unsigned int
80 | # endif
81 |
82 | # define RIPEMD160_CBLOCK 64
83 | # define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4)
84 | # define RIPEMD160_DIGEST_LENGTH 20
85 |
86 | typedef struct RIPEMD160state_st {
87 | RIPEMD160_LONG A, B, C, D, E;
88 | RIPEMD160_LONG Nl, Nh;
89 | RIPEMD160_LONG data[RIPEMD160_LBLOCK];
90 | unsigned int num;
91 | } RIPEMD160_CTX;
92 |
93 | # ifdef OPENSSL_FIPS
94 | int private_RIPEMD160_Init(RIPEMD160_CTX *c);
95 | # endif
96 | int RIPEMD160_Init(RIPEMD160_CTX *c);
97 | int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len);
98 | int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
99 | unsigned char *RIPEMD160(const unsigned char *d, size_t n, unsigned char *md);
100 | void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 |
105 | #endif
106 |
--------------------------------------------------------------------------------
/library/src/main/jni/mosquitto/lib/callbacks.c:
--------------------------------------------------------------------------------
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 | #include "config.h"
18 |
19 | #include "mosquitto.h"
20 | #include "mosquitto_internal.h"
21 |
22 |
23 | void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int))
24 | {
25 | pthread_mutex_lock(&mosq->callback_mutex);
26 | mosq->on_connect = on_connect;
27 | pthread_mutex_unlock(&mosq->callback_mutex);
28 | }
29 |
30 | void mosquitto_connect_with_flags_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int))
31 | {
32 | pthread_mutex_lock(&mosq->callback_mutex);
33 | mosq->on_connect_with_flags = on_connect;
34 | pthread_mutex_unlock(&mosq->callback_mutex);
35 | }
36 |
37 | void mosquitto_connect_v5_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int, const mosquitto_property *))
38 | {
39 | pthread_mutex_lock(&mosq->callback_mutex);
40 | mosq->on_connect_v5 = on_connect;
41 | pthread_mutex_unlock(&mosq->callback_mutex);
42 | }
43 |
44 | void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int))
45 | {
46 | pthread_mutex_lock(&mosq->callback_mutex);
47 | mosq->on_disconnect = on_disconnect;
48 | pthread_mutex_unlock(&mosq->callback_mutex);
49 | }
50 |
51 | void mosquitto_disconnect_v5_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int, const mosquitto_property *))
52 | {
53 | pthread_mutex_lock(&mosq->callback_mutex);
54 | mosq->on_disconnect_v5 = on_disconnect;
55 | pthread_mutex_unlock(&mosq->callback_mutex);
56 | }
57 |
58 | void mosquitto_publish_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int))
59 | {
60 | pthread_mutex_lock(&mosq->callback_mutex);
61 | mosq->on_publish = on_publish;
62 | pthread_mutex_unlock(&mosq->callback_mutex);
63 | }
64 |
65 | void mosquitto_publish_v5_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int, int, const mosquitto_property *props))
66 | {
67 | pthread_mutex_lock(&mosq->callback_mutex);
68 | mosq->on_publish_v5 = on_publish;
69 | pthread_mutex_unlock(&mosq->callback_mutex);
70 | }
71 |
72 | void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *))
73 | {
74 | pthread_mutex_lock(&mosq->callback_mutex);
75 | mosq->on_message = on_message;
76 | pthread_mutex_unlock(&mosq->callback_mutex);
77 | }
78 |
79 | void mosquitto_message_v5_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *, const mosquitto_property *props))
80 | {
81 | pthread_mutex_lock(&mosq->callback_mutex);
82 | mosq->on_message_v5 = on_message;
83 | pthread_mutex_unlock(&mosq->callback_mutex);
84 | }
85 |
86 | void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *))
87 | {
88 | pthread_mutex_lock(&mosq->callback_mutex);
89 | mosq->on_subscribe = on_subscribe;
90 | pthread_mutex_unlock(&mosq->callback_mutex);
91 | }
92 |
93 | void mosquitto_subscribe_v5_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *props))
94 | {
95 | pthread_mutex_lock(&mosq->callback_mutex);
96 | mosq->on_subscribe_v5 = on_subscribe;
97 | pthread_mutex_unlock(&mosq->callback_mutex);
98 | }
99 |
100 | void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int))
101 | {
102 | pthread_mutex_lock(&mosq->callback_mutex);
103 | mosq->on_unsubscribe = on_unsubscribe;
104 | pthread_mutex_unlock(&mosq->callback_mutex);
105 | }
106 |
107 | void mosquitto_unsubscribe_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, const mosquitto_property *props))
108 | {
109 | pthread_mutex_lock(&mosq->callback_mutex);
110 | mosq->on_unsubscribe_v5 = on_unsubscribe;
111 | pthread_mutex_unlock(&mosq->callback_mutex);
112 | }
113 |
114 | void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *))
115 | {
116 | pthread_mutex_lock(&mosq->log_callback_mutex);
117 | mosq->on_log = on_log;
118 | pthread_mutex_unlock(&mosq->log_callback_mutex);
119 | }
120 |
121 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/rc2.h:
--------------------------------------------------------------------------------
1 | /* crypto/rc2/rc2.h */
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_RC2_H
60 | # define HEADER_RC2_H
61 |
62 | # include /* OPENSSL_NO_RC2, RC2_INT */
63 | # ifdef OPENSSL_NO_RC2
64 | # error RC2 is disabled.
65 | # endif
66 |
67 | # define RC2_ENCRYPT 1
68 | # define RC2_DECRYPT 0
69 |
70 | # define RC2_BLOCK 8
71 | # define RC2_KEY_LENGTH 16
72 |
73 | #ifdef __cplusplus
74 | extern "C" {
75 | #endif
76 |
77 | typedef struct rc2_key_st {
78 | RC2_INT data[64];
79 | } RC2_KEY;
80 |
81 | # ifdef OPENSSL_FIPS
82 | void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
83 | int bits);
84 | # endif
85 | void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits);
86 | void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out,
87 | RC2_KEY *key, int enc);
88 | void RC2_encrypt(unsigned long *data, RC2_KEY *key);
89 | void RC2_decrypt(unsigned long *data, RC2_KEY *key);
90 | void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
91 | RC2_KEY *ks, unsigned char *iv, int enc);
92 | void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
93 | long length, RC2_KEY *schedule, unsigned char *ivec,
94 | int *num, int enc);
95 | void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
96 | long length, RC2_KEY *schedule, unsigned char *ivec,
97 | int *num);
98 |
99 | #ifdef __cplusplus
100 | }
101 | #endif
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/stack.h:
--------------------------------------------------------------------------------
1 | /* crypto/stack/stack.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_STACK_H
60 | # define HEADER_STACK_H
61 |
62 | #ifdef __cplusplus
63 | extern "C" {
64 | #endif
65 |
66 | typedef struct stack_st {
67 | int num;
68 | char **data;
69 | int sorted;
70 | int num_alloc;
71 | int (*comp) (const void *, const void *);
72 | } _STACK; /* Use STACK_OF(...) instead */
73 |
74 | # define M_sk_num(sk) ((sk) ? (sk)->num:-1)
75 | # define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
76 |
77 | int sk_num(const _STACK *);
78 | void *sk_value(const _STACK *, int);
79 |
80 | void *sk_set(_STACK *, int, void *);
81 |
82 | _STACK *sk_new(int (*cmp) (const void *, const void *));
83 | _STACK *sk_new_null(void);
84 | void sk_free(_STACK *);
85 | void sk_pop_free(_STACK *st, void (*func) (void *));
86 | _STACK *sk_deep_copy(_STACK *, void *(*)(void *), void (*)(void *));
87 | int sk_insert(_STACK *sk, void *data, int where);
88 | void *sk_delete(_STACK *st, int loc);
89 | void *sk_delete_ptr(_STACK *st, void *p);
90 | int sk_find(_STACK *st, void *data);
91 | int sk_find_ex(_STACK *st, void *data);
92 | int sk_push(_STACK *st, void *data);
93 | int sk_unshift(_STACK *st, void *data);
94 | void *sk_shift(_STACK *st);
95 | void *sk_pop(_STACK *st);
96 | void sk_zero(_STACK *st);
97 | int (*sk_set_cmp_func(_STACK *sk, int (*c) (const void *, const void *)))
98 | (const void *, const void *);
99 | _STACK *sk_dup(_STACK *st);
100 | void sk_sort(_STACK *st);
101 | int sk_is_sorted(const _STACK *st);
102 |
103 | #ifdef __cplusplus
104 | }
105 | #endif
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/hmac.h:
--------------------------------------------------------------------------------
1 | /* crypto/hmac/hmac.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 | #ifndef HEADER_HMAC_H
59 | # define HEADER_HMAC_H
60 |
61 | # include
62 |
63 | # ifdef OPENSSL_NO_HMAC
64 | # error HMAC is disabled.
65 | # endif
66 |
67 | # include
68 |
69 | # define HMAC_MAX_MD_CBLOCK 128/* largest known is SHA512 */
70 |
71 | #ifdef __cplusplus
72 | extern "C" {
73 | #endif
74 |
75 | typedef struct hmac_ctx_st {
76 | const EVP_MD *md;
77 | EVP_MD_CTX md_ctx;
78 | EVP_MD_CTX i_ctx;
79 | EVP_MD_CTX o_ctx;
80 | unsigned int key_length;
81 | unsigned char key[HMAC_MAX_MD_CBLOCK];
82 | } HMAC_CTX;
83 |
84 | # define HMAC_size(e) (EVP_MD_size((e)->md))
85 |
86 | void HMAC_CTX_init(HMAC_CTX *ctx);
87 | void HMAC_CTX_cleanup(HMAC_CTX *ctx);
88 |
89 | /* deprecated */
90 | # define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx)
91 |
92 | /* deprecated */
93 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md);
94 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
95 | const EVP_MD *md, ENGINE *impl);
96 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
97 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
98 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
99 | const unsigned char *d, size_t n, unsigned char *md,
100 | unsigned int *md_len);
101 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
102 |
103 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
104 |
105 | #ifdef __cplusplus
106 | }
107 | #endif
108 |
109 | #endif
110 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/cast.h:
--------------------------------------------------------------------------------
1 | /* crypto/cast/cast.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_CAST_H
60 | # define HEADER_CAST_H
61 |
62 | #ifdef __cplusplus
63 | extern "C" {
64 | #endif
65 |
66 | # include
67 |
68 | # ifdef OPENSSL_NO_CAST
69 | # error CAST is disabled.
70 | # endif
71 |
72 | # define CAST_ENCRYPT 1
73 | # define CAST_DECRYPT 0
74 |
75 | # define CAST_LONG unsigned int
76 |
77 | # define CAST_BLOCK 8
78 | # define CAST_KEY_LENGTH 16
79 |
80 | typedef struct cast_key_st {
81 | CAST_LONG data[32];
82 | int short_key; /* Use reduced rounds for short key */
83 | } CAST_KEY;
84 |
85 | # ifdef OPENSSL_FIPS
86 | void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
87 | # endif
88 | void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
89 | void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
90 | const CAST_KEY *key, int enc);
91 | void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key);
92 | void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key);
93 | void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out,
94 | long length, const CAST_KEY *ks, unsigned char *iv,
95 | int enc);
96 | void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
97 | long length, const CAST_KEY *schedule,
98 | unsigned char *ivec, int *num, int enc);
99 | void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
100 | long length, const CAST_KEY *schedule,
101 | unsigned char *ivec, int *num);
102 |
103 | #ifdef __cplusplus
104 | }
105 | #endif
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/txt_db.h:
--------------------------------------------------------------------------------
1 | /* crypto/txt_db/txt_db.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_TXT_DB_H
60 | # define HEADER_TXT_DB_H
61 |
62 | # include
63 | # ifndef OPENSSL_NO_BIO
64 | # include
65 | # endif
66 | # include
67 | # include
68 |
69 | # define DB_ERROR_OK 0
70 | # define DB_ERROR_MALLOC 1
71 | # define DB_ERROR_INDEX_CLASH 2
72 | # define DB_ERROR_INDEX_OUT_OF_RANGE 3
73 | # define DB_ERROR_NO_INDEX 4
74 | # define DB_ERROR_INSERT_INDEX_CLASH 5
75 |
76 | #ifdef __cplusplus
77 | extern "C" {
78 | #endif
79 |
80 | typedef OPENSSL_STRING *OPENSSL_PSTRING;
81 | DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING)
82 |
83 | typedef struct txt_db_st {
84 | int num_fields;
85 | STACK_OF(OPENSSL_PSTRING) *data;
86 | LHASH_OF(OPENSSL_STRING) **index;
87 | int (**qual) (OPENSSL_STRING *);
88 | long error;
89 | long arg1;
90 | long arg2;
91 | OPENSSL_STRING *arg_row;
92 | } TXT_DB;
93 |
94 | # ifndef OPENSSL_NO_BIO
95 | TXT_DB *TXT_DB_read(BIO *in, int num);
96 | long TXT_DB_write(BIO *out, TXT_DB *db);
97 | # else
98 | TXT_DB *TXT_DB_read(char *in, int num);
99 | long TXT_DB_write(char *out, TXT_DB *db);
100 | # endif
101 | int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *),
102 | LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
103 | void TXT_DB_free(TXT_DB *db);
104 | OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx,
105 | OPENSSL_STRING *value);
106 | int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value);
107 |
108 | #ifdef __cplusplus
109 | }
110 | #endif
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/idea.h:
--------------------------------------------------------------------------------
1 | /* crypto/idea/idea.h */
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_IDEA_H
60 | # define HEADER_IDEA_H
61 |
62 | # include /* IDEA_INT, OPENSSL_NO_IDEA */
63 |
64 | # ifdef OPENSSL_NO_IDEA
65 | # error IDEA is disabled.
66 | # endif
67 |
68 | # define IDEA_ENCRYPT 1
69 | # define IDEA_DECRYPT 0
70 |
71 | # define IDEA_BLOCK 8
72 | # define IDEA_KEY_LENGTH 16
73 |
74 | #ifdef __cplusplus
75 | extern "C" {
76 | #endif
77 |
78 | typedef struct idea_key_st {
79 | IDEA_INT data[9][6];
80 | } IDEA_KEY_SCHEDULE;
81 |
82 | const char *idea_options(void);
83 | void idea_ecb_encrypt(const unsigned char *in, unsigned char *out,
84 | IDEA_KEY_SCHEDULE *ks);
85 | # ifdef OPENSSL_FIPS
86 | void private_idea_set_encrypt_key(const unsigned char *key,
87 | IDEA_KEY_SCHEDULE *ks);
88 | # endif
89 | void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);
90 | void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
91 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out,
92 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
93 | int enc);
94 | void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,
95 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
96 | int *num, int enc);
97 | void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out,
98 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
99 | int *num);
100 | void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 |
105 | #endif
106 |
--------------------------------------------------------------------------------
/library/src/main/jni/openssl/include/openssl/md4.h:
--------------------------------------------------------------------------------
1 | /* crypto/md4/md4.h */
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 | * All rights reserved.
4 | *
5 | * This package is an SSL implementation written
6 | * by Eric Young (eay@cryptsoft.com).
7 | * The implementation was written so as to conform with Netscapes SSL.
8 | *
9 | * This library is free for commercial and non-commercial use as long as
10 | * the following conditions are aheared to. The following conditions
11 | * apply to all code found in this distribution, be it the RC4, RSA,
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 | * included with this distribution is covered by the same copyright terms
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 | *
16 | * Copyright remains Eric Young's, and as such any Copyright notices in
17 | * the code are not to be removed.
18 | * If this package is used in a product, Eric Young should be given attribution
19 | * as the author of the parts of the library used.
20 | * This can be in the form of a textual message at program startup or
21 | * in documentation (online or textual) provided with the package.
22 | *
23 | * Redistribution and use in source and binary forms, with or without
24 | * modification, are permitted provided that the following conditions
25 | * are met:
26 | * 1. Redistributions of source code must retain the copyright
27 | * notice, this list of conditions and the following disclaimer.
28 | * 2. Redistributions in binary form must reproduce the above copyright
29 | * notice, this list of conditions and the following disclaimer in the
30 | * documentation and/or other materials provided with the distribution.
31 | * 3. All advertising materials mentioning features or use of this software
32 | * must display the following acknowledgement:
33 | * "This product includes cryptographic software written by
34 | * Eric Young (eay@cryptsoft.com)"
35 | * The word 'cryptographic' can be left out if the rouines from the library
36 | * being used are not cryptographic related :-).
37 | * 4. If you include any Windows specific code (or a derivative thereof) from
38 | * the apps directory (application code) you must include an acknowledgement:
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 | *
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 | * SUCH DAMAGE.
52 | *
53 | * The licence and distribution terms for any publically available version or
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be
55 | * copied and put under another distribution licence
56 | * [including the GNU Public Licence.]
57 | */
58 |
59 | #ifndef HEADER_MD4_H
60 | # define HEADER_MD4_H
61 |
62 | # include
63 | # include
64 |
65 | #ifdef __cplusplus
66 | extern "C" {
67 | #endif
68 |
69 | # ifdef OPENSSL_NO_MD4
70 | # error MD4 is disabled.
71 | # endif
72 |
73 | /*-
74 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 | * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then !
76 | * ! MD4_LONG_LOG2 has to be defined along. !
77 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 | */
79 |
80 | # if defined(__LP32__)
81 | # define MD4_LONG unsigned long
82 | # elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
83 | # define MD4_LONG unsigned long
84 | # define MD4_LONG_LOG2 3
85 | /*
86 | * _CRAY note. I could declare short, but I have no idea what impact
87 | * does it have on performance on none-T3E machines. I could declare
88 | * int, but at least on C90 sizeof(int) can be chosen at compile time.
89 | * So I've chosen long...
90 | *
91 | */
92 | # else
93 | # define MD4_LONG unsigned int
94 | # endif
95 |
96 | # define MD4_CBLOCK 64
97 | # define MD4_LBLOCK (MD4_CBLOCK/4)
98 | # define MD4_DIGEST_LENGTH 16
99 |
100 | typedef struct MD4state_st {
101 | MD4_LONG A, B, C, D;
102 | MD4_LONG Nl, Nh;
103 | MD4_LONG data[MD4_LBLOCK];
104 | unsigned int num;
105 | } MD4_CTX;
106 |
107 | # ifdef OPENSSL_FIPS
108 | int private_MD4_Init(MD4_CTX *c);
109 | # endif
110 | int MD4_Init(MD4_CTX *c);
111 | int MD4_Update(MD4_CTX *c, const void *data, size_t len);
112 | int MD4_Final(unsigned char *md, MD4_CTX *c);
113 | unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md);
114 | void MD4_Transform(MD4_CTX *c, const unsigned char *b);
115 | #ifdef __cplusplus
116 | }
117 | #endif
118 |
119 | #endif
120 |
--------------------------------------------------------------------------------