├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── google-services.json
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── proxydroid
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── armeabi-v7a
│ │ │ ├── cntlm
│ │ │ ├── gost
│ │ │ ├── gost.sh
│ │ │ ├── proxy.sh
│ │ │ └── redsocks
│ │ ├── pages
│ │ │ └── about.html
│ │ └── x86
│ │ │ ├── cntlm
│ │ │ ├── gost
│ │ │ ├── gost.sh
│ │ │ ├── proxy.sh
│ │ │ └── redsocks
│ ├── cpp
│ │ ├── CMakeLists.txt
│ │ ├── exec
│ │ │ ├── CMakeLists.txt
│ │ │ └── termExec.cpp
│ │ ├── libevent
│ │ │ ├── CMakeLists.txt
│ │ │ ├── arc4random.c
│ │ │ ├── buffer.c
│ │ │ ├── buffer_iocp.c
│ │ │ ├── bufferevent-internal.h
│ │ │ ├── bufferevent.c
│ │ │ ├── bufferevent_async.c
│ │ │ ├── bufferevent_filter.c
│ │ │ ├── bufferevent_openssl.c
│ │ │ ├── bufferevent_pair.c
│ │ │ ├── bufferevent_ratelim.c
│ │ │ ├── bufferevent_sock.c
│ │ │ ├── changelist-internal.h
│ │ │ ├── compat
│ │ │ │ └── sys
│ │ │ │ │ └── queue.h
│ │ │ ├── config.h
│ │ │ ├── defer-internal.h
│ │ │ ├── devpoll.c
│ │ │ ├── epoll.c
│ │ │ ├── epoll_sub.c
│ │ │ ├── evbuffer-internal.h
│ │ │ ├── evdns.c
│ │ │ ├── evdns.h
│ │ │ ├── event-internal.h
│ │ │ ├── event.c
│ │ │ ├── event.h
│ │ │ ├── event_iocp.c
│ │ │ ├── event_tagging.c
│ │ │ ├── evhttp.h
│ │ │ ├── evmap-internal.h
│ │ │ ├── evmap.c
│ │ │ ├── evport.c
│ │ │ ├── evrpc-internal.h
│ │ │ ├── evrpc.c
│ │ │ ├── evrpc.h
│ │ │ ├── evsignal-internal.h
│ │ │ ├── evthread-internal.h
│ │ │ ├── evthread.c
│ │ │ ├── evthread_pthread.c
│ │ │ ├── evthread_win32.c
│ │ │ ├── evutil.c
│ │ │ ├── evutil.h
│ │ │ ├── evutil_rand.c
│ │ │ ├── ht-internal.h
│ │ │ ├── http-internal.h
│ │ │ ├── http.c
│ │ │ ├── include
│ │ │ │ └── event2
│ │ │ │ │ ├── buffer.h
│ │ │ │ │ ├── buffer_compat.h
│ │ │ │ │ ├── bufferevent.h
│ │ │ │ │ ├── bufferevent_compat.h
│ │ │ │ │ ├── bufferevent_ssl.h
│ │ │ │ │ ├── bufferevent_struct.h
│ │ │ │ │ ├── dns.h
│ │ │ │ │ ├── dns_compat.h
│ │ │ │ │ ├── dns_struct.h
│ │ │ │ │ ├── event-config.h
│ │ │ │ │ ├── event.h
│ │ │ │ │ ├── event_compat.h
│ │ │ │ │ ├── event_struct.h
│ │ │ │ │ ├── http.h
│ │ │ │ │ ├── http_compat.h
│ │ │ │ │ ├── http_struct.h
│ │ │ │ │ ├── keyvalq_struct.h
│ │ │ │ │ ├── listener.h
│ │ │ │ │ ├── rpc.h
│ │ │ │ │ ├── rpc_compat.h
│ │ │ │ │ ├── rpc_struct.h
│ │ │ │ │ ├── tag.h
│ │ │ │ │ ├── tag_compat.h
│ │ │ │ │ ├── thread.h
│ │ │ │ │ └── util.h
│ │ │ ├── iocp-internal.h
│ │ │ ├── ipv6-internal.h
│ │ │ ├── kqueue.c
│ │ │ ├── listener.c
│ │ │ ├── log-internal.h
│ │ │ ├── log.c
│ │ │ ├── minheap-internal.h
│ │ │ ├── mm-internal.h
│ │ │ ├── poll.c
│ │ │ ├── ratelim-internal.h
│ │ │ ├── select.c
│ │ │ ├── signal.c
│ │ │ ├── strlcpy-internal.h
│ │ │ ├── strlcpy.c
│ │ │ ├── util-internal.h
│ │ │ └── win32select.c
│ │ └── redsocks
│ │ │ ├── CMakeLists.txt
│ │ │ ├── base.c
│ │ │ ├── base.h
│ │ │ ├── base64.c
│ │ │ ├── base64.h
│ │ │ ├── config.h
│ │ │ ├── dnstc.c
│ │ │ ├── dnstc.h
│ │ │ ├── http-auth.c
│ │ │ ├── http-auth.h
│ │ │ ├── http-connect.c
│ │ │ ├── http-relay.c
│ │ │ ├── libc-compat.h
│ │ │ ├── libevent-compat.h
│ │ │ ├── list.h
│ │ │ ├── log.c
│ │ │ ├── log.h
│ │ │ ├── main.c
│ │ │ ├── main.h
│ │ │ ├── md5.c
│ │ │ ├── md5.h
│ │ │ ├── parser.c
│ │ │ ├── parser.h
│ │ │ ├── reddns.c
│ │ │ ├── redsocks.c
│ │ │ ├── redsocks.h
│ │ │ ├── redudp.c
│ │ │ ├── redudp.h
│ │ │ ├── socks4.c
│ │ │ ├── socks5.c
│ │ │ ├── socks5.h
│ │ │ ├── utils.c
│ │ │ ├── utils.h
│ │ │ └── version.h
│ ├── java
│ │ ├── com
│ │ │ ├── btr
│ │ │ │ └── proxy
│ │ │ │ │ └── selector
│ │ │ │ │ └── pac
│ │ │ │ │ ├── PacProxySelector.java
│ │ │ │ │ ├── PacScriptMethods.java
│ │ │ │ │ ├── PacScriptParser.java
│ │ │ │ │ ├── PacScriptSource.java
│ │ │ │ │ ├── Proxy.java
│ │ │ │ │ ├── ProxyEvaluationException.java
│ │ │ │ │ ├── ProxyException.java
│ │ │ │ │ ├── RhinoPacScriptParser.java
│ │ │ │ │ ├── ScriptMethods.java
│ │ │ │ │ └── UrlPacScriptSource.java
│ │ │ └── ksmaze
│ │ │ │ └── android
│ │ │ │ └── preference
│ │ │ │ └── ListPreferenceMultiSelect.java
│ │ └── org
│ │ │ └── proxydroid
│ │ │ ├── AppManager.java
│ │ │ ├── BypassListActivity.java
│ │ │ ├── ConnectivityBroadcastReceiver.java
│ │ │ ├── DomainValidator.java
│ │ │ ├── Exec.java
│ │ │ ├── FileArrayAdapter.java
│ │ │ ├── FileChooser.java
│ │ │ ├── InnerSocketBuilder.java
│ │ │ ├── Profile.java
│ │ │ ├── ProxyDroid.java
│ │ │ ├── ProxyDroidApplication.java
│ │ │ ├── ProxyDroidReceiver.java
│ │ │ ├── ProxyDroidService.java
│ │ │ ├── ProxyDroidWidgetProvider.java
│ │ │ ├── ProxyedApp.java
│ │ │ └── utils
│ │ │ ├── Base64.java
│ │ │ ├── Constraints.java
│ │ │ ├── ImageLoader.java
│ │ │ ├── ImageLoaderFactory.java
│ │ │ ├── Option.java
│ │ │ ├── RegexValidator.java
│ │ │ └── Utils.java
│ └── res
│ │ ├── color
│ │ ├── button_text_selector.xml
│ │ └── selector.xml
│ │ ├── drawable-hdpi-v11
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-hdpi-v9
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-hdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_stat_proxydroid.png
│ │ ├── ing.png
│ │ ├── off.png
│ │ └── on.png
│ │ ├── drawable-ldpi-v11
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-ldpi-v9
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-ldpi
│ │ ├── ic_launcher.png
│ │ ├── ic_stat_proxydroid.png
│ │ ├── ing.png
│ │ ├── off.png
│ │ └── on.png
│ │ ├── drawable-mdpi-v11
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-mdpi-v9
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-mdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_stat_proxydroid.png
│ │ ├── ing.png
│ │ ├── off.png
│ │ └── on.png
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xhdpi-v11
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-xhdpi-v9
│ │ └── ic_stat_proxydroid.png
│ │ ├── drawable-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_stat_proxydroid.png
│ │ ├── ing.png
│ │ ├── off.png
│ │ └── on.png
│ │ ├── drawable
│ │ ├── button_gray.xml
│ │ ├── button_selector.xml
│ │ ├── button_white.xml
│ │ ├── ic_launcher_background.xml
│ │ └── sym_def_app_icon.png
│ │ ├── layout
│ │ ├── alert_dialog_text_entry.xml
│ │ ├── bypass_list.xml
│ │ ├── bypass_list_item.xml
│ │ ├── file_view.xml
│ │ ├── layout_apps.xml
│ │ ├── layout_apps_item.xml
│ │ ├── overlay.xml
│ │ └── proxydroid_appwidget.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ ├── values-fr
│ │ └── strings.xml
│ │ ├── values-pt
│ │ └── strings.xml
│ │ ├── values-ru
│ │ └── strings.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ └── strings.xml
│ │ ├── xml-v14
│ │ └── proxydroid_preference.xml
│ │ └── xml
│ │ ├── proxydroid_appwidget_provider.xml
│ │ └── proxydroid_preference.xml
│ └── test
│ └── java
│ └── org
│ └── proxydroid
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── privacy_policy.md
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | gen/
3 | local.properties
4 | *.iml
5 | .idea
6 | .cxx
7 | target/
8 | obj/
9 | libs/armeabi/redsocks
10 | libs/armeabi/shadowsocks
11 | libs/armeabi/shrpx
12 | gen-external-apklibs/
13 | classes/
14 | .gradle
15 | build/
16 | app/release
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## INTRO
2 |
3 | Global Proxy App for Android System
4 |
5 | ProxyDroid is distributed under GPLv3 with many other open source software,
6 | here is a list of them:
7 |
8 | * cntlm - authentication proxy: http://cntlm.sourceforge.net/
9 | * redsocks - transparent socks redirector: http://darkk.net.ru/redsocks/
10 | * netfilter/iptables - NAT module: http://www.netfilter.org/
11 | * transproxy - transparent proxy for HTTP: http://transproxy.sourceforge.net/
12 | * stunnel - multiplatform SSL tunneling proxy: http://www.stunnel.org/
13 |
14 | ## TRAVIS CI STATUS
15 |
16 | [](http://travis-ci.org/madeye/proxydroid)
17 |
18 | [Nightly Builds](http://buildbot.sinaapp.com)
19 |
20 | ## PREREQUISITES
21 |
22 | * JDK 1.6+
23 | * Maven 3.0.5
24 | * Android SDK r17+
25 | * Android NDK r8+
26 |
27 | * Local Maven Dependencies
28 |
29 | Use Maven Android SDK Deployer to install all android related dependencies.
30 |
31 | ```bash
32 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git
33 | pushd maven-android-sdk-deployer
34 | export ANDROID_HOME=/path/to/android/sdk
35 | mvn install -P 4.1
36 | popd
37 | ```
38 |
39 | ## BUILD
40 |
41 | Invoke the building like this
42 |
43 | ```bash
44 | mvn clean install
45 | ```
46 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.google.gms.google-services'
3 | apply plugin: 'io.fabric'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.0"
8 | defaultConfig {
9 | applicationId "org.proxydroid"
10 | minSdkVersion 16
11 | targetSdkVersion 29
12 | versionCode 72
13 | versionName "3.2.0"
14 |
15 | ndk {
16 | // Specifies the ABI configurations of your native
17 | // libraries Gradle should build and package with your APK.
18 | abiFilters 'x86', 'x86_64', 'armeabi-v7a', '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 |
32 | externalNativeBuild {
33 | cmake {
34 | version '3.10.2'
35 | path "src/main/cpp/CMakeLists.txt"
36 | }
37 | }
38 | }
39 |
40 | configurations {
41 | compile.exclude group: "junit", module: "junit"
42 | }
43 |
44 | dependencies {
45 | implementation fileTree(dir: 'libs', include: ['*.jar'])
46 | implementation 'androidx.appcompat:appcompat:1.1.0'
47 | implementation 'com.google.android.material:material:1.0.0'
48 | implementation 'com.googlecode.json-simple:json-simple:1.1.1'
49 | implementation 'org.mozilla:rhino:1.7.11'
50 | implementation 'com.google.firebase:firebase-core:17.2.1'
51 | implementation 'com.google.firebase:firebase-ads:18.3.0'
52 | implementation 'com.google.firebase:firebase-analytics:17.2.1'
53 | implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
54 | }
55 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "1096038627085",
4 | "firebase_url": "https://proxydroid-eebb6.firebaseio.com",
5 | "project_id": "proxydroid-eebb6",
6 | "storage_bucket": "proxydroid-eebb6.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:1096038627085:android:2626ff7369ac1bc788a244",
12 | "android_client_info": {
13 | "package_name": "org.proxydroid"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "1096038627085-rk8st1497vge5t9hlft638b9rcdkpe47.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "org.proxydroid",
22 | "certificate_hash": "a3568c8b31e1b2d1c2d9edd21b4e37c7c13ce26f"
23 | }
24 | },
25 | {
26 | "client_id": "1096038627085-de6572k5m9tbsmu2v5hm607vqe313pir.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyAvllRwaStt15XJNQrBRaCOVwJkUsnTbx8"
33 | }
34 | ],
35 | "services": {
36 | "appinvite_service": {
37 | "other_platform_oauth_client": [
38 | {
39 | "client_id": "1096038627085-de6572k5m9tbsmu2v5hm607vqe313pir.apps.googleusercontent.com",
40 | "client_type": 3
41 | }
42 | ]
43 | }
44 | },
45 | "admob_app_id": "ca-app-pub-9097031975646651~9376680322"
46 | }
47 | ],
48 | "configuration_version": "1"
49 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/org/proxydroid/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package org.proxydroid;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 | import androidx.test.platform.app.InstrumentationRegistry;
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("org.proxydroid", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
21 |
22 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
39 |
43 |
46 |
47 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a/cntlm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madeye/proxydroid/3de979eb8ef70e12ab5f23ff343c6778f339c956/app/src/main/assets/armeabi-v7a/cntlm
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a/gost:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madeye/proxydroid/3de979eb8ef70e12ab5f23ff343c6778f339c956/app/src/main/assets/armeabi-v7a/gost
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a/gost.sh:
--------------------------------------------------------------------------------
1 | #!/system/bin/sh
2 |
3 | DIR=$1
4 | SRC=$2
5 | DST=$3
6 |
7 | PATH=$DIR:$PATH
8 |
9 | gost $SRC $DST &> $DIR/gost.log &
10 | echo "$!" > $DIR/gost.pid
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a/proxy.sh:
--------------------------------------------------------------------------------
1 | #!/system/bin/sh
2 |
3 | DIR=$1
4 | action=$2
5 | type=$3
6 | host=$4
7 | port=$5
8 | auth=$6
9 | user=$7
10 | pass=$8
11 |
12 | PATH=$DIR:$PATH
13 |
14 | case $action in
15 | start)
16 |
17 | echo "
18 | base {
19 | log_debug = off;
20 | log_info = off;
21 | log = stderr;
22 | daemon = on;
23 | redirector = iptables;
24 | }
25 | " >$DIR/redsocks.conf
26 | proxy_port=8123
27 |
28 | case $type in
29 | http)
30 | proxy_port=8124
31 | case $auth in
32 | true)
33 | echo "
34 | redsocks {
35 | local_ip = 127.0.0.1;
36 | local_port = 8123;
37 | ip = $host;
38 | port = $port;
39 | type = http-relay;
40 | login = \"$user\";
41 | password = \"$pass\";
42 | }
43 | redsocks {
44 | local_ip = 0.0.0.0;
45 | local_port = 8124;
46 | ip = $host;
47 | port = $port;
48 | type = http-connect;
49 | login = \"$user\";
50 | password = \"$pass\";
51 | }
52 | " >>$DIR/redsocks.conf
53 | ;;
54 | false)
55 | echo "
56 | redsocks {
57 | local_ip = 127.0.0.1;
58 | local_port = 8123;
59 | ip = $host;
60 | port = $port;
61 | type = http-relay;
62 | }
63 | redsocks {
64 | local_ip = 0.0.0.0;
65 | local_port = 8124;
66 | ip = $host;
67 | port = $port;
68 | type = http-connect;
69 | }
70 | " >>$DIR/redsocks.conf
71 | ;;
72 | esac
73 | ;;
74 | socks5)
75 | case $auth in
76 | true)
77 | echo "
78 | redsocks {
79 | local_ip = 0.0.0.0;
80 | local_port = 8123;
81 | ip = $host;
82 | port = $port;
83 | type = socks5;
84 | login = \"$user\";
85 | password = \"$pass\";
86 | }
87 | " >>$DIR/redsocks.conf
88 | ;;
89 | false)
90 | echo "
91 | redsocks {
92 | local_ip = 0.0.0.0;
93 | local_port = 8123;
94 | ip = $host;
95 | port = $port;
96 | type = socks5;
97 | }
98 | " >>$DIR/redsocks.conf
99 | ;;
100 | esac
101 | ;;
102 | socks4)
103 | case $auth in
104 | true)
105 | echo "
106 | redsocks {
107 | local_ip = 0.0.0.0;
108 | local_port = 8123;
109 | ip = $host;
110 | port = $port;
111 | type = socks4;
112 | login = \"$user\";
113 | password = \"$pass\";
114 | }
115 | " >>$DIR/redsocks.conf
116 | ;;
117 | false)
118 | echo "
119 | redsocks {
120 | local_ip = 0.0.0.0;
121 | local_port = 8123;
122 | ip = $host;
123 | port = $port;
124 | type = socks4;
125 | }
126 | " >>$DIR/redsocks.conf
127 | ;;
128 | esac
129 | ;;
130 | esac
131 |
132 | $DIR/redsocks -p $DIR/redsocks.pid -c $DIR/redsocks.conf
133 | iptables -A INPUT -i ap+ -p tcp --dport 8123 -j ACCEPT
134 | iptables -A INPUT -i ap+ -p tcp --dport 8124 -j ACCEPT
135 | iptables -A INPUT -i wlan1 -p tcp --dport 8123 -j ACCEPT
136 | iptables -A INPUT -i wlan1 -p tcp --dport 8124 -j ACCEPT
137 | iptables -A INPUT -i lo -p tcp --dport 8123 -j ACCEPT
138 | iptables -A INPUT -i lo -p tcp --dport 8124 -j ACCEPT
139 | iptables -A INPUT -p tcp --dport 8123 -j DROP
140 | iptables -A INPUT -p tcp --dport 8124 -j DROP
141 | iptables -t nat -A PREROUTING -i ap+ -p tcp -d 192.168.43.1/24 -j RETURN
142 | iptables -t nat -A PREROUTING -i ap+ -p tcp -j REDIRECT --to $proxy_port
143 | iptables -t nat -A PREROUTING -i wlan1 -p tcp -d 192.168.43.1/24 -j RETURN
144 | iptables -t nat -A PREROUTING -i wlan1 -p tcp -j REDIRECT --to $proxy_port
145 | ;;
146 | stop)
147 |
148 | iptables -t nat -D PREROUTING -i ap+ -p tcp -d 192.168.43.1/24 -j RETURN
149 | iptables -t nat -D PREROUTING -i ap+ -p tcp -j REDIRECT --to 8123
150 | iptables -t nat -D PREROUTING -i ap+ -p tcp -j REDIRECT --to 8124
151 | iptables -D INPUT -i ap+ -p tcp --dport 8123 -j ACCEPT
152 | iptables -D INPUT -i ap+ -p tcp --dport 8124 -j ACCEPT
153 | iptables -t nat -D PREROUTING -i wlan1 -p tcp -d 192.168.43.1/24 -j RETURN
154 | iptables -t nat -D PREROUTING -i wlan1 -p tcp -j REDIRECT --to 8123
155 | iptables -t nat -D PREROUTING -i wlan1 -p tcp -j REDIRECT --to 8124
156 | iptables -D INPUT -i wlan1 -p tcp --dport 8123 -j ACCEPT
157 | iptables -D INPUT -i wlan1 -p tcp --dport 8124 -j ACCEPT
158 | iptables -D INPUT -i lo -p tcp --dport 8123 -j ACCEPT
159 | iptables -D INPUT -i lo -p tcp --dport 8124 -j ACCEPT
160 | iptables -D INPUT -p tcp --dport 8123 -j DROP
161 | iptables -D INPUT -p tcp --dport 8124 -j DROP
162 |
163 | killall -9 redsocks
164 | killall -9 cntlm
165 | killall -9 gost
166 |
167 | kill -9 `cat $DIR/redsocks.pid`
168 |
169 | rm $DIR/redsocks.pid
170 |
171 | rm $DIR/redsocks.conf
172 | esac
173 |
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a/redsocks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madeye/proxydroid/3de979eb8ef70e12ab5f23ff343c6778f339c956/app/src/main/assets/armeabi-v7a/redsocks
--------------------------------------------------------------------------------
/app/src/main/assets/x86/cntlm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madeye/proxydroid/3de979eb8ef70e12ab5f23ff343c6778f339c956/app/src/main/assets/x86/cntlm
--------------------------------------------------------------------------------
/app/src/main/assets/x86/gost:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madeye/proxydroid/3de979eb8ef70e12ab5f23ff343c6778f339c956/app/src/main/assets/x86/gost
--------------------------------------------------------------------------------
/app/src/main/assets/x86/gost.sh:
--------------------------------------------------------------------------------
1 | #!/system/bin/sh
2 |
3 | DIR=$1
4 | SRC=$2
5 | DST=$3
6 |
7 | PATH=$DIR:$PATH
8 |
9 | gost $SRC $DST &> $DIR/gost.log &
10 | echo "$!" > $DIR/gost.pid
--------------------------------------------------------------------------------
/app/src/main/assets/x86/proxy.sh:
--------------------------------------------------------------------------------
1 | #!/system/bin/sh
2 |
3 | DIR=$1
4 | action=$2
5 | type=$3
6 | host=$4
7 | port=$5
8 | auth=$6
9 | user=$7
10 | pass=$8
11 |
12 | PATH=$DIR:$PATH
13 |
14 | case $action in
15 | start)
16 |
17 | echo "
18 | base {
19 | log_debug = off;
20 | log_info = off;
21 | log = stderr;
22 | daemon = on;
23 | redirector = iptables;
24 | }
25 | " >$DIR/redsocks.conf
26 | proxy_port=8123
27 |
28 | case $type in
29 | http)
30 | proxy_port=8124
31 | case $auth in
32 | true)
33 | echo "
34 | redsocks {
35 | local_ip = 127.0.0.1;
36 | local_port = 8123;
37 | ip = $host;
38 | port = $port;
39 | type = http-relay;
40 | login = \"$user\";
41 | password = \"$pass\";
42 | }
43 | redsocks {
44 | local_ip = 0.0.0.0;
45 | local_port = 8124;
46 | ip = $host;
47 | port = $port;
48 | type = http-connect;
49 | login = \"$user\";
50 | password = \"$pass\";
51 | }
52 | " >>$DIR/redsocks.conf
53 | ;;
54 | false)
55 | echo "
56 | redsocks {
57 | local_ip = 127.0.0.1;
58 | local_port = 8123;
59 | ip = $host;
60 | port = $port;
61 | type = http-relay;
62 | }
63 | redsocks {
64 | local_ip = 0.0.0.0;
65 | local_port = 8124;
66 | ip = $host;
67 | port = $port;
68 | type = http-connect;
69 | }
70 | " >>$DIR/redsocks.conf
71 | ;;
72 | esac
73 | ;;
74 | socks5)
75 | case $auth in
76 | true)
77 | echo "
78 | redsocks {
79 | local_ip = 0.0.0.0;
80 | local_port = 8123;
81 | ip = $host;
82 | port = $port;
83 | type = socks5;
84 | login = \"$user\";
85 | password = \"$pass\";
86 | }
87 | " >>$DIR/redsocks.conf
88 | ;;
89 | false)
90 | echo "
91 | redsocks {
92 | local_ip = 0.0.0.0;
93 | local_port = 8123;
94 | ip = $host;
95 | port = $port;
96 | type = socks5;
97 | }
98 | " >>$DIR/redsocks.conf
99 | ;;
100 | esac
101 | ;;
102 | socks4)
103 | case $auth in
104 | true)
105 | echo "
106 | redsocks {
107 | local_ip = 0.0.0.0;
108 | local_port = 8123;
109 | ip = $host;
110 | port = $port;
111 | type = socks4;
112 | login = \"$user\";
113 | password = \"$pass\";
114 | }
115 | " >>$DIR/redsocks.conf
116 | ;;
117 | false)
118 | echo "
119 | redsocks {
120 | local_ip = 0.0.0.0;
121 | local_port = 8123;
122 | ip = $host;
123 | port = $port;
124 | type = socks4;
125 | }
126 | " >>$DIR/redsocks.conf
127 | ;;
128 | esac
129 | ;;
130 | esac
131 |
132 | $DIR/redsocks -p $DIR/redsocks.pid -c $DIR/redsocks.conf
133 | iptables -A INPUT -i ap+ -p tcp --dport 8123 -j ACCEPT
134 | iptables -A INPUT -i ap+ -p tcp --dport 8124 -j ACCEPT
135 | iptables -A INPUT -i wlan1 -p tcp --dport 8123 -j ACCEPT
136 | iptables -A INPUT -i wlan1 -p tcp --dport 8124 -j ACCEPT
137 | iptables -A INPUT -i lo -p tcp --dport 8123 -j ACCEPT
138 | iptables -A INPUT -i lo -p tcp --dport 8124 -j ACCEPT
139 | iptables -A INPUT -p tcp --dport 8123 -j DROP
140 | iptables -A INPUT -p tcp --dport 8124 -j DROP
141 | iptables -t nat -A PREROUTING -i ap+ -p tcp -d 192.168.43.1/24 -j RETURN
142 | iptables -t nat -A PREROUTING -i ap+ -p tcp -j REDIRECT --to $proxy_port
143 | iptables -t nat -A PREROUTING -i wlan1 -p tcp -d 192.168.43.1/24 -j RETURN
144 | iptables -t nat -A PREROUTING -i wlan1 -p tcp -j REDIRECT --to $proxy_port
145 | ;;
146 | stop)
147 |
148 | iptables -t nat -D PREROUTING -i ap+ -p tcp -d 192.168.43.1/24 -j RETURN
149 | iptables -t nat -D PREROUTING -i ap+ -p tcp -j REDIRECT --to 8123
150 | iptables -t nat -D PREROUTING -i ap+ -p tcp -j REDIRECT --to 8124
151 | iptables -D INPUT -i ap+ -p tcp --dport 8123 -j ACCEPT
152 | iptables -D INPUT -i ap+ -p tcp --dport 8124 -j ACCEPT
153 | iptables -t nat -D PREROUTING -i wlan1 -p tcp -d 192.168.43.1/24 -j RETURN
154 | iptables -t nat -D PREROUTING -i wlan1 -p tcp -j REDIRECT --to 8123
155 | iptables -t nat -D PREROUTING -i wlan1 -p tcp -j REDIRECT --to 8124
156 | iptables -D INPUT -i wlan1 -p tcp --dport 8123 -j ACCEPT
157 | iptables -D INPUT -i wlan1 -p tcp --dport 8124 -j ACCEPT
158 | iptables -D INPUT -i lo -p tcp --dport 8123 -j ACCEPT
159 | iptables -D INPUT -i lo -p tcp --dport 8124 -j ACCEPT
160 | iptables -D INPUT -p tcp --dport 8123 -j DROP
161 | iptables -D INPUT -p tcp --dport 8124 -j DROP
162 |
163 | killall -9 redsocks
164 | killall -9 cntlm
165 | killall -9 gost
166 |
167 | kill -9 `cat $DIR/redsocks.pid`
168 |
169 | rm $DIR/redsocks.pid
170 |
171 | rm $DIR/redsocks.conf
172 | esac
173 |
--------------------------------------------------------------------------------
/app/src/main/assets/x86/redsocks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madeye/proxydroid/3de979eb8ef70e12ab5f23ff343c6778f339c956/app/src/main/assets/x86/redsocks
--------------------------------------------------------------------------------
/app/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | add_subdirectory(exec)
4 | add_subdirectory(libevent)
5 | add_subdirectory(redsocks)
6 |
--------------------------------------------------------------------------------
/app/src/main/cpp/exec/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(exec SHARED
2 | termExec.cpp)
3 |
4 | # Include libraries needed for exec lib
5 | target_link_libraries(exec
6 | android
7 | dl
8 | log)
9 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(event STATIC
2 | buffer.c
3 | bufferevent.c
4 | bufferevent_filter.c
5 | bufferevent_pair.c
6 | bufferevent_ratelim.c
7 | bufferevent_sock.c
8 | epoll.c
9 | epoll_sub.c
10 | evdns.c
11 | event.c
12 | event_tagging.c
13 | evmap.c
14 | evrpc.c
15 | evthread.c
16 | evthread_pthread.c
17 | evutil.c
18 | evutil_rand.c
19 | http.c
20 | listener.c
21 | log.c
22 | poll.c
23 | select.c
24 | signal.c
25 | strlcpy.c
26 | )
27 |
28 | target_include_directories(event
29 | PUBLIC
30 | ${CMAKE_CURRENT_SOURCE_DIR}
31 | ${CMAKE_CURRENT_SOURCE_DIR}/include
32 | )
33 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/changelist-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _CHANGELIST_H_
27 | #define _CHANGELIST_H_
28 |
29 | /*
30 | A "changelist" is a list of all the fd status changes that should be made
31 | between calls to the backend's dispatch function. There are a few reasons
32 | that a backend would want to queue changes like this rather than processing
33 | them immediately.
34 |
35 | 1) Sometimes applications will add and delete the same event more than
36 | once between calls to dispatch. Processing these changes immediately
37 | is needless, and potentially expensive (especially if we're on a system
38 | that makes one syscall per changed event).
39 |
40 | 2) Sometimes we can coalesce multiple changes on the same fd into a single
41 | syscall if we know about them in advance. For example, epoll can do an
42 | add and a delete at the same time, but only if we have found out about
43 | both of them before we tell epoll.
44 |
45 | 3) Sometimes adding an event that we immediately delete can cause
46 | unintended consequences: in kqueue, this makes pending events get
47 | reported spuriously.
48 | */
49 |
50 | #include "event2/util.h"
51 |
52 | /** Represents a */
53 | struct event_change {
54 | /** The fd or signal whose events are to be changed */
55 | evutil_socket_t fd;
56 | /* The events that were enabled on the fd before any of these changes
57 | were made. May include EV_READ or EV_WRITE. */
58 | short old_events;
59 |
60 | /* The changes that we want to make in reading and writing on this fd.
61 | * If this is a signal, then read_change has EV_CHANGE_SIGNAL set,
62 | * and write_change is unused. */
63 | ev_uint8_t read_change;
64 | ev_uint8_t write_change;
65 | };
66 |
67 | /* Flags for read_change and write_change. */
68 |
69 | /* If set, add the event. */
70 | #define EV_CHANGE_ADD 0x01
71 | /* If set, delete the event. Exclusive with EV_CHANGE_ADD */
72 | #define EV_CHANGE_DEL 0x02
73 | /* If set, this event refers a signal, not an fd. */
74 | #define EV_CHANGE_SIGNAL EV_SIGNAL
75 | /* Set for persistent events. Currently not used. */
76 | #define EV_CHANGE_PERSIST EV_PERSIST
77 | /* Set for adding edge-triggered events. */
78 | #define EV_CHANGE_ET EV_ET
79 |
80 | /* The value of fdinfo_size that a backend should use if it is letting
81 | * changelist handle its add and delete functions. */
82 | #define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int)
83 |
84 | /** Set up the data fields in a changelist. */
85 | void event_changelist_init(struct event_changelist *changelist);
86 | /** Remove every change in the changelist, and make corresponding changes
87 | * in the event maps in the base. This function is generally used right
88 | * after making all the changes in the changelist. */
89 | void event_changelist_remove_all(struct event_changelist *changelist,
90 | struct event_base *base);
91 | /** Free all memory held in a changelist. */
92 | void event_changelist_freemem(struct event_changelist *changelist);
93 |
94 | /** Implementation of eventop_add that queues the event in a changelist. */
95 | int event_changelist_add(struct event_base *base, evutil_socket_t fd, short old, short events,
96 | void *p);
97 | /** Implementation of eventop_del that queues the event in a changelist. */
98 | int event_changelist_del(struct event_base *base, evutil_socket_t fd, short old, short events,
99 | void *p);
100 |
101 | #endif
102 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/defer-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _DEFER_INTERNAL_H_
27 | #define _DEFER_INTERNAL_H_
28 |
29 | #ifdef __cplusplus
30 | extern "C" {
31 | #endif
32 |
33 | #include "event2/event-config.h"
34 | #include
35 |
36 | struct deferred_cb;
37 |
38 | typedef void (*deferred_cb_fn)(struct deferred_cb *, void *);
39 |
40 | /** A deferred_cb is a callback that can be scheduled to run as part of
41 | * an event_base's event_loop, rather than running immediately. */
42 | struct deferred_cb {
43 | /** Links to the adjacent active (pending) deferred_cb objects. */
44 | TAILQ_ENTRY (deferred_cb) cb_next;
45 | /** True iff this deferred_cb is pending in an event_base. */
46 | unsigned queued : 1;
47 | /** The function to execute when the callback runs. */
48 | deferred_cb_fn cb;
49 | /** The function's second argument. */
50 | void *arg;
51 | };
52 |
53 | /** A deferred_cb_queue is a list of deferred_cb that we can add to and run. */
54 | struct deferred_cb_queue {
55 | /** Lock used to protect the queue. */
56 | void *lock;
57 |
58 | /** How many entries are in the queue? */
59 | int active_count;
60 |
61 | /** Function called when adding to the queue from another thread. */
62 | void (*notify_fn)(struct deferred_cb_queue *, void *);
63 | void *notify_arg;
64 |
65 | /** Deferred callback management: a list of deferred callbacks to
66 | * run active the active events. */
67 | TAILQ_HEAD (deferred_cb_list, deferred_cb) deferred_cb_list;
68 | };
69 |
70 | /**
71 | Initialize an empty, non-pending deferred_cb.
72 |
73 | @param deferred The deferred_cb structure to initialize.
74 | @param cb The function to run when the deferred_cb executes.
75 | @param arg The function's second argument.
76 | */
77 | void event_deferred_cb_init(struct deferred_cb *, deferred_cb_fn, void *);
78 | /**
79 | Cancel a deferred_cb if it is currently scheduled in an event_base.
80 | */
81 | void event_deferred_cb_cancel(struct deferred_cb_queue *, struct deferred_cb *);
82 | /**
83 | Activate a deferred_cb if it is not currently scheduled in an event_base.
84 | */
85 | void event_deferred_cb_schedule(struct deferred_cb_queue *, struct deferred_cb *);
86 |
87 | #define LOCK_DEFERRED_QUEUE(q) \
88 | EVLOCK_LOCK((q)->lock, 0)
89 | #define UNLOCK_DEFERRED_QUEUE(q) \
90 | EVLOCK_UNLOCK((q)->lock, 0)
91 |
92 | #ifdef __cplusplus
93 | }
94 | #endif
95 |
96 | void event_deferred_cb_queue_init(struct deferred_cb_queue *);
97 | struct deferred_cb_queue *event_base_get_deferred_cb_queue(struct event_base *);
98 |
99 | #endif /* _EVENT_INTERNAL_H_ */
100 |
101 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/epoll_sub.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2003-2009 Niels Provos
3 | * Copyright 2009-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #include
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | int
37 | epoll_create(int size)
38 | {
39 | #if !defined(__NR_epoll_create) && defined(__NR_epoll_create1)
40 | if (size <= 0) {
41 | errno = EINVAL;
42 | return -1;
43 | }
44 | return (syscall(__NR_epoll_create1, 0));
45 | #else
46 | return (syscall(__NR_epoll_create, size));
47 | #endif
48 | }
49 |
50 | int
51 | epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
52 | {
53 |
54 | return (syscall(__NR_epoll_ctl, epfd, op, fd, event));
55 | }
56 |
57 | int
58 | epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
59 | {
60 | #if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait)
61 | return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0));
62 | #else
63 | return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout));
64 | #endif
65 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/evdns.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVDNS_H_
28 | #define _EVDNS_H_
29 |
30 | /** @file evdns.h
31 |
32 | A dns subsystem for Libevent.
33 |
34 | The header is deprecated in Libevent 2.0 and later; please
35 | use instead. Depending on what functionality you
36 | need, you may also want to include more of the other
37 | headers.
38 | */
39 |
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #endif /* _EVDNS_H_ */
46 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/event.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT_H_
28 | #define _EVENT_H_
29 |
30 | /** @file event.h
31 |
32 | A library for writing event-driven network servers.
33 |
34 | The header is deprecated in Libevent 2.0 and later; please
35 | use instead. Depending on what functionality you
36 | need, you may also want to include more of the other event2/
37 | headers.
38 | */
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | #include
45 | #ifdef _EVENT_HAVE_SYS_TYPES_H
46 | #include
47 | #endif
48 | #ifdef _EVENT_HAVE_SYS_TIME_H
49 | #include
50 | #endif
51 | #ifdef _EVENT_HAVE_STDINT_H
52 | #include
53 | #endif
54 | #include
55 |
56 | /* For int types. */
57 | #include
58 |
59 | #ifdef WIN32
60 | #ifndef WIN32_LEAN_AND_MEAN
61 | #define WIN32_LEAN_AND_MEAN
62 | #endif
63 | #include
64 | #include
65 | #undef WIN32_LEAN_AND_MEAN
66 | typedef unsigned char u_char;
67 | typedef unsigned short u_short;
68 | #endif
69 |
70 | #include
71 | #include
72 | #include
73 | #include
74 | #include
75 | #include
76 | #include
77 | #include
78 | #include
79 | #include
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 |
85 | #endif /* _EVENT_H_ */
86 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/evhttp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2000-2007 Niels Provos
3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVHTTP_H_
28 | #define _EVHTTP_H_
29 |
30 | /** @file evhttp.h
31 |
32 | An http implementation subsystem for Libevent.
33 |
34 | The header is deprecated in Libevent 2.0 and later; please
35 | use instead. Depending on what functionality you
36 | need, you may also want to include more of the other
37 | headers.
38 | */
39 |
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #endif /* _EVHTTP_H_ */
46 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/evmap-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _EVMAP_H_
27 | #define _EVMAP_H_
28 |
29 | /** @file evmap-internal.h
30 | *
31 | * An event_map is a utility structure to map each fd or signal to zero or
32 | * more events. Functions to manipulate event_maps should only be used from
33 | * inside libevent. They generally need to hold the lock on the corresponding
34 | * event_base.
35 | **/
36 |
37 | struct event_base;
38 | struct event;
39 |
40 | /** Initialize an event_map for use.
41 | */
42 | void evmap_io_initmap(struct event_io_map* ctx);
43 | void evmap_signal_initmap(struct event_signal_map* ctx);
44 |
45 | /** Remove all entries from an event_map.
46 |
47 | @param ctx the map to clear.
48 | */
49 | void evmap_io_clear(struct event_io_map* ctx);
50 | void evmap_signal_clear(struct event_signal_map* ctx);
51 |
52 | /** Add an IO event (some combination of EV_READ or EV_WRITE) to an
53 | event_base's list of events on a given file descriptor, and tell the
54 | underlying eventops about the fd if its state has changed.
55 |
56 | Requires that ev is not already added.
57 |
58 | @param base the event_base to operate on.
59 | @param fd the file descriptor corresponding to ev.
60 | @param ev the event to add.
61 | */
62 | int evmap_io_add(struct event_base *base, evutil_socket_t fd, struct event *ev);
63 | /** Remove an IO event (some combination of EV_READ or EV_WRITE) to an
64 | event_base's list of events on a given file descriptor, and tell the
65 | underlying eventops about the fd if its state has changed.
66 |
67 | @param base the event_base to operate on.
68 | @param fd the file descriptor corresponding to ev.
69 | @param ev the event to remove.
70 | */
71 | int evmap_io_del(struct event_base *base, evutil_socket_t fd, struct event *ev);
72 | /** Active the set of events waiting on an event_base for a given fd.
73 |
74 | @param base the event_base to operate on.
75 | @param fd the file descriptor that has become active.
76 | @param events a bitmask of EV_READ|EV_WRITE|EV_ET.
77 | */
78 | void evmap_io_active(struct event_base *base, evutil_socket_t fd, short events);
79 |
80 |
81 | /* These functions behave in the same way as evmap_io_*, except they work on
82 | * signals rather than fds. signals use a linear map everywhere; fds use
83 | * either a linear map or a hashtable. */
84 | int evmap_signal_add(struct event_base *base, int signum, struct event *ev);
85 | int evmap_signal_del(struct event_base *base, int signum, struct event *ev);
86 | void evmap_signal_active(struct event_base *base, evutil_socket_t signum, int ncalls);
87 |
88 | void *evmap_io_get_fdinfo(struct event_io_map *ctx, evutil_socket_t fd);
89 |
90 | void evmap_check_integrity(struct event_base *base);
91 |
92 | #endif /* _EVMAP_H_ */
93 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/evrpc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVRPC_H_
28 | #define _EVRPC_H_
29 |
30 | /** @file evrpc.h
31 |
32 | An RPC system for Libevent.
33 |
34 | The header is deprecated in Libevent 2.0 and later; please
35 | use instead. Depending on what functionality you
36 | need, you may also want to include more of the other
37 | headers.
38 | */
39 |
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #endif /* _EVRPC_H_ */
46 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/evsignal-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2000-2007 Niels Provos
3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVSIGNAL_H_
28 | #define _EVSIGNAL_H_
29 |
30 | #ifndef evutil_socket_t
31 | #include "event2/util.h"
32 | #endif
33 | #include
34 |
35 | typedef void (*ev_sighandler_t)(int);
36 |
37 | /* Data structure for the default signal-handling implementation in signal.c
38 | */
39 | struct evsig_info {
40 | /* Event watching ev_signal_pair[1] */
41 | struct event ev_signal;
42 | /* Socketpair used to send notifications from the signal handler */
43 | evutil_socket_t ev_signal_pair[2];
44 | /* True iff we've added the ev_signal event yet. */
45 | int ev_signal_added;
46 | /* Count of the number of signals we're currently watching. */
47 | int ev_n_signals_added;
48 |
49 | /* Array of previous signal handler objects before Libevent started
50 | * messing with them. Used to restore old signal handlers. */
51 | #ifdef _EVENT_HAVE_SIGACTION
52 | struct sigaction **sh_old;
53 | #else
54 | ev_sighandler_t **sh_old;
55 | #endif
56 | /* Size of sh_old. */
57 | int sh_old_max;
58 | };
59 | int evsig_init(struct event_base *);
60 | void evsig_dealloc(struct event_base *);
61 |
62 | void evsig_set_base(struct event_base *base);
63 |
64 | #endif /* _EVSIGNAL_H_ */
65 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/evutil.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _EVUTIL_H_
27 | #define _EVUTIL_H_
28 |
29 | /** @file evutil.h
30 |
31 | Utility and compatibility functions for Libevent.
32 |
33 | The header is deprecated in Libevent 2.0 and later; please
34 | use instead.
35 | */
36 |
37 | #include
38 |
39 | #endif /* _EVUTIL_H_ */
40 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/bufferevent_compat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
3 | * Copyright (c) 2000-2007 Niels Provos
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. The name of the author may not be used to endorse or promote products
15 | * derived from this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 | #ifndef _EVENT2_BUFFEREVENT_COMPAT_H_
29 | #define _EVENT2_BUFFEREVENT_COMPAT_H_
30 |
31 | #define evbuffercb bufferevent_data_cb
32 | #define everrorcb bufferevent_event_cb
33 |
34 | /**
35 | Create a new bufferevent for an fd.
36 |
37 | This function is deprecated. Use bufferevent_socket_new and
38 | bufferevent_set_callbacks instead.
39 |
40 | Libevent provides an abstraction on top of the regular event callbacks.
41 | This abstraction is called a buffered event. A buffered event provides
42 | input and output buffers that get filled and drained automatically. The
43 | user of a buffered event no longer deals directly with the I/O, but
44 | instead is reading from input and writing to output buffers.
45 |
46 | Once initialized, the bufferevent structure can be used repeatedly with
47 | bufferevent_enable() and bufferevent_disable().
48 |
49 | When read enabled the bufferevent will try to read from the file descriptor
50 | and call the read callback. The write callback is executed whenever the
51 | output buffer is drained below the write low watermark, which is 0 by
52 | default.
53 |
54 | If multiple bases are in use, bufferevent_base_set() must be called before
55 | enabling the bufferevent for the first time.
56 |
57 | @deprecated This function is deprecated because it uses the current
58 | event base, and as such can be error prone for multithreaded programs.
59 | Use bufferevent_socket_new() instead.
60 |
61 | @param fd the file descriptor from which data is read and written to.
62 | This file descriptor is not allowed to be a pipe(2).
63 | @param readcb callback to invoke when there is data to be read, or NULL if
64 | no callback is desired
65 | @param writecb callback to invoke when the file descriptor is ready for
66 | writing, or NULL if no callback is desired
67 | @param errorcb callback to invoke when there is an error on the file
68 | descriptor
69 | @param cbarg an argument that will be supplied to each of the callbacks
70 | (readcb, writecb, and errorcb)
71 | @return a pointer to a newly allocated bufferevent struct, or NULL if an
72 | error occurred
73 | @see bufferevent_base_set(), bufferevent_free()
74 | */
75 | struct bufferevent *bufferevent_new(evutil_socket_t fd,
76 | evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
77 |
78 |
79 | /**
80 | Set the read and write timeout for a buffered event.
81 |
82 | @param bufev the bufferevent to be modified
83 | @param timeout_read the read timeout
84 | @param timeout_write the write timeout
85 | */
86 | void bufferevent_settimeout(struct bufferevent *bufev,
87 | int timeout_read, int timeout_write);
88 |
89 | #define EVBUFFER_READ BEV_EVENT_READING
90 | #define EVBUFFER_WRITE BEV_EVENT_WRITING
91 | #define EVBUFFER_EOF BEV_EVENT_EOF
92 | #define EVBUFFER_ERROR BEV_EVENT_ERROR
93 | #define EVBUFFER_TIMEOUT BEV_EVENT_TIMEOUT
94 |
95 | /** macro for getting access to the input buffer of a bufferevent */
96 | #define EVBUFFER_INPUT(x) bufferevent_get_input(x)
97 | /** macro for getting access to the output buffer of a bufferevent */
98 | #define EVBUFFER_OUTPUT(x) bufferevent_get_output(x)
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/bufferevent_ssl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _EVENT2_BUFFEREVENT_SSL_H_
27 | #define _EVENT2_BUFFEREVENT_SSL_H_
28 |
29 | /** @file event2/bufferevent_ssl.h
30 |
31 | OpenSSL support for bufferevents.
32 | */
33 |
34 | #include
35 | #include
36 | #include
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* This is what openssl's SSL objects are underneath. */
43 | struct ssl_st;
44 |
45 | /**
46 | The state of an SSL object to be used when creating a new
47 | SSL bufferevent.
48 | */
49 | enum bufferevent_ssl_state {
50 | BUFFEREVENT_SSL_OPEN = 0,
51 | BUFFEREVENT_SSL_CONNECTING = 1,
52 | BUFFEREVENT_SSL_ACCEPTING = 2
53 | };
54 |
55 | #if defined(_EVENT_HAVE_OPENSSL) || defined(_EVENT_IN_DOXYGEN)
56 | /**
57 | Create a new SSL bufferevent to send its data over another bufferevent.
58 |
59 | @param base An event_base to use to detect reading and writing. It
60 | must also be the base for the underlying bufferevent.
61 | @param underlying A socket to use for this SSL
62 | @param ssl A SSL* object from openssl.
63 | @param state The current state of the SSL connection
64 | @param options One or more bufferevent_options
65 | @return A new bufferevent on success, or NULL on failure
66 | */
67 | struct bufferevent *
68 | bufferevent_openssl_filter_new(struct event_base *base,
69 | struct bufferevent *underlying,
70 | struct ssl_st *ssl,
71 | enum bufferevent_ssl_state state,
72 | int options);
73 |
74 | /**
75 | Create a new SSL bufferevent to send its data over an SSL * on a socket.
76 |
77 | @param base An event_base to use to detect reading and writing
78 | @param fd A socket to use for this SSL
79 | @param ssl A SSL* object from openssl.
80 | @param state The current state of the SSL connection
81 | @param options One or more bufferevent_options
82 | @return A new bufferevent on success, or NULL on failure.
83 | */
84 | struct bufferevent *
85 | bufferevent_openssl_socket_new(struct event_base *base,
86 | evutil_socket_t fd,
87 | struct ssl_st *ssl,
88 | enum bufferevent_ssl_state state,
89 | int options);
90 |
91 | /** Return the underlying openssl SSL * object for an SSL bufferevent. */
92 | struct ssl_st *
93 | bufferevent_openssl_get_ssl(struct bufferevent *bufev);
94 |
95 | /** Tells a bufferevent to begin SSL renegotiation. */
96 | int bufferevent_ssl_renegotiate(struct bufferevent *bev);
97 |
98 | /** Return the most recent OpenSSL error reported on an SSL bufferevent. */
99 | unsigned long bufferevent_get_openssl_error(struct bufferevent *bev);
100 |
101 | #endif
102 |
103 | #ifdef __cplusplus
104 | }
105 | #endif
106 |
107 | #endif /* _EVENT2_BUFFEREVENT_SSL_H_ */
108 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/bufferevent_struct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_BUFFEREVENT_STRUCT_H_
28 | #define _EVENT2_BUFFEREVENT_STRUCT_H_
29 |
30 | /** @file event2/bufferevent_struct.h
31 |
32 | Data structures for bufferevents. Using these structures may hurt forward
33 | compatibility with later versions of Libevent: be careful!
34 |
35 | @deprecated Use of bufferevent_struct.h is completely deprecated; these
36 | structures are only exposed for backward compatibility with programs
37 | written before Libevent 2.0 that used them.
38 | */
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | #include
45 | #ifdef _EVENT_HAVE_SYS_TYPES_H
46 | #include
47 | #endif
48 | #ifdef _EVENT_HAVE_SYS_TIME_H
49 | #include
50 | #endif
51 |
52 | /* For int types. */
53 | #include
54 | /* For struct event */
55 | #include
56 |
57 | struct event_watermark {
58 | size_t low;
59 | size_t high;
60 | };
61 |
62 | /**
63 | Shared implementation of a bufferevent.
64 |
65 | This type is exposed only because it was exposed in previous versions,
66 | and some people's code may rely on manipulating it. Otherwise, you
67 | should really not rely on the layout, size, or contents of this structure:
68 | it is fairly volatile, and WILL change in future versions of the code.
69 | **/
70 | struct bufferevent {
71 | /** Event base for which this bufferevent was created. */
72 | struct event_base *ev_base;
73 | /** Pointer to a table of function pointers to set up how this
74 | bufferevent behaves. */
75 | const struct bufferevent_ops *be_ops;
76 |
77 | /** A read event that triggers when a timeout has happened or a socket
78 | is ready to read data. Only used by some subtypes of
79 | bufferevent. */
80 | struct event ev_read;
81 | /** A write event that triggers when a timeout has happened or a socket
82 | is ready to write data. Only used by some subtypes of
83 | bufferevent. */
84 | struct event ev_write;
85 |
86 | /** An input buffer. Only the bufferevent is allowed to add data to
87 | this buffer, though the user is allowed to drain it. */
88 | struct evbuffer *input;
89 |
90 | /** An input buffer. Only the bufferevent is allowed to drain data
91 | from this buffer, though the user is allowed to add it. */
92 | struct evbuffer *output;
93 |
94 | struct event_watermark wm_read;
95 | struct event_watermark wm_write;
96 |
97 | bufferevent_data_cb readcb;
98 | bufferevent_data_cb writecb;
99 | /* This should be called 'eventcb', but renaming it would break
100 | * backward compatibility */
101 | bufferevent_event_cb errorcb;
102 | void *cbarg;
103 |
104 | struct timeval timeout_read;
105 | struct timeval timeout_write;
106 |
107 | /** Events that are currently enabled: currently EV_READ and EV_WRITE
108 | are supported. */
109 | short enabled;
110 | };
111 |
112 | #ifdef __cplusplus
113 | }
114 | #endif
115 |
116 | #endif /* _EVENT2_BUFFEREVENT_STRUCT_H_ */
117 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/dns_struct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_DNS_STRUCT_H_
28 | #define _EVENT2_DNS_STRUCT_H_
29 |
30 | /** @file event2/dns_struct.h
31 |
32 | Data structures for dns. Using these structures may hurt forward
33 | compatibility with later versions of Libevent: be careful!
34 |
35 | */
36 |
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | #include
42 | #ifdef _EVENT_HAVE_SYS_TYPES_H
43 | #include
44 | #endif
45 | #ifdef _EVENT_HAVE_SYS_TIME_H
46 | #include
47 | #endif
48 |
49 | /* For int types. */
50 | #include
51 |
52 | /*
53 | * Structures used to implement a DNS server.
54 | */
55 |
56 | struct evdns_server_request {
57 | int flags;
58 | int nquestions;
59 | struct evdns_server_question **questions;
60 | };
61 | struct evdns_server_question {
62 | int type;
63 | #ifdef __cplusplus
64 | int dns_question_class;
65 | #else
66 | /* You should refer to this field as "dns_question_class". The
67 | * name "class" works in C for backward compatibility, and will be
68 | * removed in a future version. (1.5 or later). */
69 | int class;
70 | #define dns_question_class class
71 | #endif
72 | char name[1];
73 | };
74 |
75 | #ifdef __cplusplus
76 | }
77 | #endif
78 |
79 | #endif /* _EVENT2_DNS_STRUCT_H_ */
80 |
81 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/event_struct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_EVENT_STRUCT_H_
28 | #define _EVENT2_EVENT_STRUCT_H_
29 |
30 | /** @file event2/event_struct.h
31 |
32 | Structures used by event.h. Using these structures directly WILL harm
33 | forward compatibility: be careful.
34 |
35 | No field declared in this file should be used directly in user code. Except
36 | for historical reasons, these fields would not be exposed at all.
37 | */
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include
44 | #ifdef _EVENT_HAVE_SYS_TYPES_H
45 | #include
46 | #endif
47 | #ifdef _EVENT_HAVE_SYS_TIME_H
48 | #include
49 | #endif
50 |
51 | /* For int types. */
52 | #include
53 |
54 | /* For evkeyvalq */
55 | #include
56 |
57 | #define EVLIST_TIMEOUT 0x01
58 | #define EVLIST_INSERTED 0x02
59 | #define EVLIST_SIGNAL 0x04
60 | #define EVLIST_ACTIVE 0x08
61 | #define EVLIST_INTERNAL 0x10
62 | #define EVLIST_INIT 0x80
63 |
64 | /* EVLIST_X_ Private space: 0x1000-0xf000 */
65 | #define EVLIST_ALL (0xf000 | 0x9f)
66 |
67 | /* Fix so that people don't have to run with */
68 | #ifndef TAILQ_ENTRY
69 | #define _EVENT_DEFINED_TQENTRY
70 | #define TAILQ_ENTRY(type) \
71 | struct { \
72 | struct type *tqe_next; /* next element */ \
73 | struct type **tqe_prev; /* address of previous next element */ \
74 | }
75 | #endif /* !TAILQ_ENTRY */
76 |
77 | #ifndef TAILQ_HEAD
78 | #define _EVENT_DEFINED_TQHEAD
79 | #define TAILQ_HEAD(name, type) \
80 | struct name { \
81 | struct type *tqh_first; \
82 | struct type **tqh_last; \
83 | }
84 | #endif
85 |
86 | struct event_base;
87 | struct event {
88 | TAILQ_ENTRY(event) ev_active_next;
89 | TAILQ_ENTRY(event) ev_next;
90 | /* for managing timeouts */
91 | union {
92 | TAILQ_ENTRY(event) ev_next_with_common_timeout;
93 | int min_heap_idx;
94 | } ev_timeout_pos;
95 | evutil_socket_t ev_fd;
96 |
97 | struct event_base *ev_base;
98 |
99 | union {
100 | /* used for io events */
101 | struct {
102 | TAILQ_ENTRY(event) ev_io_next;
103 | struct timeval ev_timeout;
104 | } ev_io;
105 |
106 | /* used by signal events */
107 | struct {
108 | TAILQ_ENTRY(event) ev_signal_next;
109 | short ev_ncalls;
110 | /* Allows deletes in callback */
111 | short *ev_pncalls;
112 | } ev_signal;
113 | } _ev;
114 |
115 | short ev_events;
116 | short ev_res; /* result passed to event callback */
117 | short ev_flags;
118 | ev_uint8_t ev_pri; /* smaller numbers are higher priority */
119 | ev_uint8_t ev_closure;
120 | struct timeval ev_timeout;
121 |
122 | /* allows us to adopt for different types of events */
123 | void (*ev_callback)(evutil_socket_t, short, void *arg);
124 | void *ev_arg;
125 | };
126 |
127 | TAILQ_HEAD (event_list, event);
128 |
129 | #ifdef _EVENT_DEFINED_TQENTRY
130 | #undef TAILQ_ENTRY
131 | #endif
132 |
133 | #ifdef _EVENT_DEFINED_TQHEAD
134 | #undef TAILQ_HEAD
135 | #endif
136 |
137 | #ifdef __cplusplus
138 | }
139 | #endif
140 |
141 | #endif /* _EVENT2_EVENT_STRUCT_H_ */
142 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/http_compat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_HTTP_COMPAT_H_
28 | #define _EVENT2_HTTP_COMPAT_H_
29 |
30 | /** @file event2/http_compat.h
31 |
32 | Potentially non-threadsafe versions of the functions in http.h: provided
33 | only for backwards compatibility.
34 |
35 | */
36 |
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | #include
42 | #ifdef _EVENT_HAVE_SYS_TYPES_H
43 | #include
44 | #endif
45 | #ifdef _EVENT_HAVE_SYS_TIME_H
46 | #include
47 | #endif
48 |
49 | /* For int types. */
50 | #include
51 |
52 | /**
53 | * Start an HTTP server on the specified address and port
54 | *
55 | * @deprecated It does not allow an event base to be specified
56 | *
57 | * @param address the address to which the HTTP server should be bound
58 | * @param port the port number on which the HTTP server should listen
59 | * @return an struct evhttp object
60 | */
61 | struct evhttp *evhttp_start(const char *address, unsigned short port);
62 |
63 | /**
64 | * A connection object that can be used to for making HTTP requests. The
65 | * connection object tries to establish the connection when it is given an
66 | * http request object.
67 | *
68 | * @deprecated It does not allow an event base to be specified
69 | */
70 | struct evhttp_connection *evhttp_connection_new(
71 | const char *address, unsigned short port);
72 |
73 | /**
74 | * Associates an event base with the connection - can only be called
75 | * on a freshly created connection object that has not been used yet.
76 | *
77 | * @deprecated XXXX Why?
78 | */
79 | void evhttp_connection_set_base(struct evhttp_connection *evcon,
80 | struct event_base *base);
81 |
82 |
83 | /** Returns the request URI */
84 | #define evhttp_request_uri evhttp_request_get_uri
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 |
90 | #endif /* _EVENT2_EVENT_COMPAT_H_ */
91 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/http_struct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_HTTP_STRUCT_H_
28 | #define _EVENT2_HTTP_STRUCT_H_
29 |
30 | /** @file event2/http_struct.h
31 |
32 | Data structures for http. Using these structures may hurt forward
33 | compatibility with later versions of Libevent: be careful!
34 |
35 | */
36 |
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | #include
42 | #ifdef _EVENT_HAVE_SYS_TYPES_H
43 | #include
44 | #endif
45 | #ifdef _EVENT_HAVE_SYS_TIME_H
46 | #include
47 | #endif
48 |
49 | /* For int types. */
50 | #include
51 |
52 | /**
53 | * the request structure that a server receives.
54 | * WARNING: expect this structure to change. I will try to provide
55 | * reasonable accessors.
56 | */
57 | struct evhttp_request {
58 | #if defined(TAILQ_ENTRY)
59 | TAILQ_ENTRY(evhttp_request) next;
60 | #else
61 | struct {
62 | struct evhttp_request *tqe_next;
63 | struct evhttp_request **tqe_prev;
64 | } next;
65 | #endif
66 |
67 | /* the connection object that this request belongs to */
68 | struct evhttp_connection *evcon;
69 | int flags;
70 | /** The request obj owns the evhttp connection and needs to free it */
71 | #define EVHTTP_REQ_OWN_CONNECTION 0x0001
72 | /** Request was made via a proxy */
73 | #define EVHTTP_PROXY_REQUEST 0x0002
74 | /** The request object is owned by the user; the user must free it */
75 | #define EVHTTP_USER_OWNED 0x0004
76 | /** The request will be used again upstack; freeing must be deferred */
77 | #define EVHTTP_REQ_DEFER_FREE 0x0008
78 | /** The request should be freed upstack */
79 | #define EVHTTP_REQ_NEEDS_FREE 0x0010
80 |
81 | struct evkeyvalq *input_headers;
82 | struct evkeyvalq *output_headers;
83 |
84 | /* address of the remote host and the port connection came from */
85 | char *remote_host;
86 | ev_uint16_t remote_port;
87 |
88 | /* cache of the hostname for evhttp_request_get_host */
89 | char *host_cache;
90 |
91 | enum evhttp_request_kind kind;
92 | enum evhttp_cmd_type type;
93 |
94 | size_t headers_size;
95 | size_t body_size;
96 |
97 | char *uri; /* uri after HTTP request was parsed */
98 | struct evhttp_uri *uri_elems; /* uri elements */
99 |
100 | char major; /* HTTP Major number */
101 | char minor; /* HTTP Minor number */
102 |
103 | int response_code; /* HTTP Response code */
104 | char *response_code_line; /* Readable response */
105 |
106 | struct evbuffer *input_buffer; /* read data */
107 | ev_int64_t ntoread;
108 | unsigned chunked:1, /* a chunked request */
109 | userdone:1; /* the user has sent all data */
110 |
111 | struct evbuffer *output_buffer; /* outgoing post or data */
112 |
113 | /* Callback */
114 | void (*cb)(struct evhttp_request *, void *);
115 | void *cb_arg;
116 |
117 | /*
118 | * Chunked data callback - call for each completed chunk if
119 | * specified. If not specified, all the data is delivered via
120 | * the regular callback.
121 | */
122 | void (*chunk_cb)(struct evhttp_request *, void *);
123 | };
124 |
125 | #ifdef __cplusplus
126 | }
127 | #endif
128 |
129 | #endif /* _EVENT2_HTTP_STRUCT_H_ */
130 |
131 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/keyvalq_struct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_EVENT_KEYVALQ_STRUCT_H_
28 | #define _EVENT2_EVENT_KEYVALQ_STRUCT_H_
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Fix so that people don't have to run with */
35 | /* XXXX This code is duplicated with event_struct.h */
36 | #ifndef TAILQ_ENTRY
37 | #define _EVENT_DEFINED_TQENTRY
38 | #define TAILQ_ENTRY(type) \
39 | struct { \
40 | struct type *tqe_next; /* next element */ \
41 | struct type **tqe_prev; /* address of previous next element */ \
42 | }
43 | #endif /* !TAILQ_ENTRY */
44 |
45 | #ifndef TAILQ_HEAD
46 | #define _EVENT_DEFINED_TQHEAD
47 | #define TAILQ_HEAD(name, type) \
48 | struct name { \
49 | struct type *tqh_first; \
50 | struct type **tqh_last; \
51 | }
52 | #endif
53 |
54 | /*
55 | * Key-Value pairs. Can be used for HTTP headers but also for
56 | * query argument parsing.
57 | */
58 | struct evkeyval {
59 | TAILQ_ENTRY(evkeyval) next;
60 |
61 | char *key;
62 | char *value;
63 | };
64 |
65 | TAILQ_HEAD (evkeyvalq, evkeyval);
66 |
67 | /* XXXX This code is duplicated with event_struct.h */
68 | #ifdef _EVENT_DEFINED_TQENTRY
69 | #undef TAILQ_ENTRY
70 | #endif
71 |
72 | #ifdef _EVENT_DEFINED_TQHEAD
73 | #undef TAILQ_HEAD
74 | #endif
75 |
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/rpc_compat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_RPC_COMPAT_H_
28 | #define _EVENT2_RPC_COMPAT_H_
29 |
30 | /** @file event2/rpc_compat.h
31 |
32 | Deprecated versions of the functions in rpc.h: provided only for
33 | backwards compatibility.
34 |
35 | */
36 |
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | /** backwards compatible accessors that work only with gcc */
42 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
43 |
44 | #undef EVTAG_ASSIGN
45 | #undef EVTAG_GET
46 | #undef EVTAG_ADD
47 |
48 | #define EVTAG_ASSIGN(msg, member, args...) \
49 | (*(msg)->base->member##_assign)(msg, ## args)
50 | #define EVTAG_GET(msg, member, args...) \
51 | (*(msg)->base->member##_get)(msg, ## args)
52 | #define EVTAG_ADD(msg, member, args...) \
53 | (*(msg)->base->member##_add)(msg, ## args)
54 | #endif
55 | #define EVTAG_LEN(msg, member) ((msg)->member##_length)
56 |
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 |
61 | #endif /* _EVENT2_EVENT_COMPAT_H_ */
62 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/rpc_struct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_RPC_STRUCT_H_
28 | #define _EVENT2_RPC_STRUCT_H_
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /** @file event2/rpc_struct.h
35 |
36 | Structures used by rpc.h. Using these structures directly may harm
37 | forward compatibility: be careful!
38 |
39 | */
40 |
41 | /**
42 | * provides information about the completed RPC request.
43 | */
44 | struct evrpc_status {
45 | #define EVRPC_STATUS_ERR_NONE 0
46 | #define EVRPC_STATUS_ERR_TIMEOUT 1
47 | #define EVRPC_STATUS_ERR_BADPAYLOAD 2
48 | #define EVRPC_STATUS_ERR_UNSTARTED 3
49 | #define EVRPC_STATUS_ERR_HOOKABORTED 4
50 | int error;
51 |
52 | /* for looking at headers or other information */
53 | struct evhttp_request *http_req;
54 | };
55 |
56 | /* the structure below needs to be synchronized with evrpc_req_generic */
57 |
58 | /* Encapsulates a request */
59 | struct evrpc {
60 | TAILQ_ENTRY(evrpc) next;
61 |
62 | /* the URI at which the request handler lives */
63 | const char* uri;
64 |
65 | /* creates a new request structure */
66 | void *(*request_new)(void *);
67 | void *request_new_arg;
68 |
69 | /* frees the request structure */
70 | void (*request_free)(void *);
71 |
72 | /* unmarshals the buffer into the proper request structure */
73 | int (*request_unmarshal)(void *, struct evbuffer *);
74 |
75 | /* creates a new reply structure */
76 | void *(*reply_new)(void *);
77 | void *reply_new_arg;
78 |
79 | /* frees the reply structure */
80 | void (*reply_free)(void *);
81 |
82 | /* verifies that the reply is valid */
83 | int (*reply_complete)(void *);
84 |
85 | /* marshals the reply into a buffer */
86 | void (*reply_marshal)(struct evbuffer*, void *);
87 |
88 | /* the callback invoked for each received rpc */
89 | void (*cb)(struct evrpc_req_generic *, void *);
90 | void *cb_arg;
91 |
92 | /* reference for further configuration */
93 | struct evrpc_base *base;
94 | };
95 |
96 | #ifdef __cplusplus
97 | }
98 | #endif
99 |
100 | #endif /* _EVENT2_RPC_STRUCT_H_ */
101 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/include/event2/tag_compat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _EVENT2_TAG_COMPAT_H_
28 | #define _EVENT2_TAG_COMPAT_H_
29 |
30 | /** @file event2/tag_compat.h
31 |
32 | Obsolete/deprecated functions from tag.h; provided only for backwards
33 | compatibility.
34 | */
35 |
36 | /**
37 | @name Misnamed functions
38 |
39 | @deprecated These macros are deprecated because their names don't follow
40 | Libevent's naming conventions. Use evtag_encode_int and
41 | evtag_encode_int64 instead.
42 |
43 | @{
44 | */
45 | #define encode_int(evbuf, number) evtag_encode_int((evbuf), (number))
46 | #define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number))
47 | /**@}*/
48 |
49 | #endif /* _EVENT2_TAG_H_ */
50 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/ipv6-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | /* Internal use only: Fake IPv6 structures and values on platforms that
28 | * do not have them */
29 |
30 | #ifndef _EVENT_IPV6_INTERNAL_H
31 | #define _EVENT_IPV6_INTERNAL_H
32 |
33 | #include
34 | #ifdef _EVENT_HAVE_SYS_SOCKET_H
35 | #include
36 | #endif
37 | #include "event2/event-config.h"
38 | #include "event2/util.h"
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | /** @file ipv6-internal.h
45 | *
46 | * Replacement types and functions for platforms that don't support ipv6
47 | * properly.
48 | */
49 |
50 | #ifndef _EVENT_HAVE_STRUCT_IN6_ADDR
51 | struct in6_addr {
52 | ev_uint8_t s6_addr[16];
53 | };
54 | #endif
55 |
56 | #ifndef _EVENT_HAVE_SA_FAMILY_T
57 | typedef int sa_family_t;
58 | #endif
59 |
60 | #ifndef _EVENT_HAVE_STRUCT_SOCKADDR_IN6
61 | struct sockaddr_in6 {
62 | /* This will fail if we find a struct sockaddr that doesn't have
63 | * sa_family as the first element. */
64 | sa_family_t sin6_family;
65 | ev_uint16_t sin6_port;
66 | struct in6_addr sin6_addr;
67 | };
68 | #endif
69 |
70 | #ifndef AF_INET6
71 | #define AF_INET6 3333
72 | #endif
73 | #ifndef PF_INET6
74 | #define PF_INET6 AF_INET6
75 | #endif
76 |
77 | #ifdef __cplusplus
78 | }
79 | #endif
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/log-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2007 Niels Provos
3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef _LOG_H_
28 | #define _LOG_H_
29 |
30 | #include "event2/util.h"
31 |
32 | #ifdef __GNUC__
33 | #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b)))
34 | #define EV_NORETURN __attribute__((noreturn))
35 | #else
36 | #define EV_CHECK_FMT(a,b)
37 | #define EV_NORETURN
38 | #endif
39 |
40 | #define _EVENT_ERR_ABORT ((int)0xdeaddead)
41 |
42 | void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
43 | void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
44 | void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
45 | void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3);
46 | void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
47 | void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
48 | void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
49 | void _event_debugx(const char *fmt, ...) EV_CHECK_FMT(1,2);
50 |
51 | #ifdef USE_DEBUG
52 | #define event_debug(x) _event_debugx x
53 | #else
54 | #define event_debug(x) do {;} while (0)
55 | #endif
56 |
57 | #undef EV_CHECK_FMT
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/mm-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _EVENT_MM_INTERNAL_H
27 | #define _EVENT_MM_INTERNAL_H
28 |
29 | #include
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | #ifndef _EVENT_DISABLE_MM_REPLACEMENT
36 | /* Internal use only: Memory allocation functions. We give them nice short
37 | * mm_names for our own use, but make sure that the symbols have longer names
38 | * so they don't conflict with other libraries (like, say, libmm). */
39 | void *event_mm_malloc_(size_t sz);
40 | void *event_mm_calloc_(size_t count, size_t size);
41 | char *event_mm_strdup_(const char *s);
42 | void *event_mm_realloc_(void *p, size_t sz);
43 | void event_mm_free_(void *p);
44 | #define mm_malloc(sz) event_mm_malloc_(sz)
45 | #define mm_calloc(count, size) event_mm_calloc_((count), (size))
46 | #define mm_strdup(s) event_mm_strdup_(s)
47 | #define mm_realloc(p, sz) event_mm_realloc_((p), (sz))
48 | #define mm_free(p) event_mm_free_(p)
49 | #else
50 | #define mm_malloc(sz) malloc(sz)
51 | #define mm_calloc(n, sz) calloc((n), (sz))
52 | #define mm_strdup(s) strdup(s)
53 | #define mm_realloc(p, sz) realloc((p), (sz))
54 | #define mm_free(p) free(p)
55 | #endif
56 |
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/ratelim-internal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
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 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote products
13 | * derived from this software without specific prior written permission.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 | #ifndef _RATELIM_INTERNAL_H_
27 | #define _RATELIM_INTERNAL_H_
28 |
29 | #ifdef __cplusplus
30 | extern "C" {
31 | #endif
32 |
33 | #include "event2/util.h"
34 |
35 | /** A token bucket is an internal structure that tracks how many bytes we are
36 | * currently willing to read or write on a given bufferevent or group of
37 | * bufferevents */
38 | struct ev_token_bucket {
39 | /** How many bytes are we willing to read or write right now? These
40 | * values are signed so that we can do "defecit spending" */
41 | ev_ssize_t read_limit, write_limit;
42 | /** When was this bucket last updated? Measured in abstract 'ticks'
43 | * relative to the token bucket configuration. */
44 | ev_uint32_t last_updated;
45 | };
46 |
47 | /** Configuration info for a token bucket or set of token buckets. */
48 | struct ev_token_bucket_cfg {
49 | /** How many bytes are we willing to read on average per tick? */
50 | size_t read_rate;
51 | /** How many bytes are we willing to read at most in any one tick? */
52 | size_t read_maximum;
53 | /** How many bytes are we willing to write on average per tick? */
54 | size_t write_rate;
55 | /** How many bytes are we willing to write at most in any one tick? */
56 | size_t write_maximum;
57 |
58 | /* How long is a tick? Note that fractions of a millisecond are
59 | * ignored. */
60 | struct timeval tick_timeout;
61 |
62 | /* How long is a tick, in milliseconds? Derived from tick_timeout. */
63 | unsigned msec_per_tick;
64 | };
65 |
66 | /** The current tick is 'current_tick': add bytes to 'bucket' as specified in
67 | * 'cfg'. */
68 | int ev_token_bucket_update(struct ev_token_bucket *bucket,
69 | const struct ev_token_bucket_cfg *cfg,
70 | ev_uint32_t current_tick);
71 |
72 | /** In which tick does 'tv' fall according to 'cfg'? Note that ticks can
73 | * overflow easily; your code needs to handle this. */
74 | ev_uint32_t ev_token_bucket_get_tick(const struct timeval *tv,
75 | const struct ev_token_bucket_cfg *cfg);
76 |
77 | /** Adjust 'bucket' to respect 'cfg', and note that it was last updated in
78 | * 'current_tick'. If 'reinitialize' is true, we are changing the
79 | * configuration of 'bucket'; otherwise, we are setting it up for the first
80 | * time.
81 | */
82 | int ev_token_bucket_init(struct ev_token_bucket *bucket,
83 | const struct ev_token_bucket_cfg *cfg,
84 | ev_uint32_t current_tick,
85 | int reinitialize);
86 |
87 | int bufferevent_remove_from_rate_limit_group_internal(struct bufferevent *bev,
88 | int unsuspend);
89 |
90 | /** Decrease the read limit of 'b' by 'n' bytes */
91 | #define ev_token_bucket_decrement_read(b,n) \
92 | do { \
93 | (b)->read_limit -= (n); \
94 | } while (0)
95 | /** Decrease the write limit of 'b' by 'n' bytes */
96 | #define ev_token_bucket_decrement_write(b,n) \
97 | do { \
98 | (b)->write_limit -= (n); \
99 | } while (0)
100 |
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 |
105 | #endif
106 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/strlcpy-internal.h:
--------------------------------------------------------------------------------
1 | #ifndef _STRLCPY_INTERNAL_H_
2 | #define _STRLCPY_INTERNAL_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "event2/event-config.h"
9 |
10 | #ifndef _EVENT_HAVE_STRLCPY
11 | #include
12 | size_t _event_strlcpy(char *dst, const char *src, size_t siz);
13 | #define strlcpy _event_strlcpy
14 | #endif
15 |
16 | #ifdef __cplusplus
17 | }
18 | #endif
19 |
20 | #endif
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libevent/strlcpy.c:
--------------------------------------------------------------------------------
1 | /* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */
2 |
3 | /*
4 | * Copyright (c) 1998 Todd C. Miller
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | * 1. Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #if defined(LIBC_SCCS) && !defined(lint)
31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $";
32 | #endif /* LIBC_SCCS and not lint */
33 |
34 | #include
35 |
36 | #include "event2/event-config.h"
37 |
38 | #ifndef _EVENT_HAVE_STRLCPY
39 | #include "strlcpy-internal.h"
40 |
41 | /*
42 | * Copy src to string dst of size siz. At most siz-1 characters
43 | * will be copied. Always NUL terminates (unless siz == 0).
44 | * Returns strlen(src); if retval >= siz, truncation occurred.
45 | */
46 | size_t
47 | _event_strlcpy(dst, src, siz)
48 | char *dst;
49 | const char *src;
50 | size_t siz;
51 | {
52 | register char *d = dst;
53 | register const char *s = src;
54 | register size_t n = siz;
55 |
56 | /* Copy as many bytes as will fit */
57 | if (n != 0 && --n != 0) {
58 | do {
59 | if ((*d++ = *s++) == 0)
60 | break;
61 | } while (--n != 0);
62 | }
63 |
64 | /* Not enough room in dst, add NUL and traverse rest of src */
65 | if (n == 0) {
66 | if (siz != 0)
67 | *d = '\0'; /* NUL-terminate dst */
68 | while (*s++)
69 | ;
70 | }
71 |
72 | return (s - src - 1); /* count does not include NUL */
73 | }
74 | #endif
75 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_executable(redsocks
2 | base.c dnstc.c http-connect.c
3 | log.c md5.c socks5.c
4 | base64.c http-auth.c http-relay.c main.c
5 | parser.c redsocks.c socks4.c utils.c
6 | )
7 |
8 | target_include_directories(redsocks
9 | PUBLIC
10 | ${CMAKE_SOURCE_DIR}/libevent
11 | ${CMAKE_SOURCE_DIR}/libevent/include
12 | )
13 |
14 | # Include libraries needed for exec lib
15 | target_link_libraries(redsocks
16 | event
17 | android
18 | dl
19 | log)
20 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/base.h:
--------------------------------------------------------------------------------
1 | #ifndef BASE_H_SUN_JUN__3_20_15_57_2007
2 | #define BASE_H_SUN_JUN__3_20_15_57_2007
3 |
4 | int getdestaddr(int fd, const struct sockaddr_in *client, const struct sockaddr_in *bindaddr, struct sockaddr_in *destaddr);
5 |
6 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
7 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
8 | #endif /* BASE_H_SUN_JUN__3_20_15_57_2007 */
9 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/base64.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * @brief Base64 encode/decode
24 | * @author Ryan Martell (with lots of Michael)
25 | */
26 |
27 | #include
28 | #include "utils.h"
29 | #include "base64.h"
30 |
31 | /* ---------------- private code */
32 | static const uint8_t map2[] =
33 | {
34 | 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36,
35 | 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff,
36 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01,
37 | 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
38 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
39 | 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
40 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b,
41 | 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
42 | 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
43 | 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33
44 | };
45 |
46 | int base64_decode(uint8_t *out, const char *in, int out_size)
47 | {
48 | int i, v;
49 | uint8_t *dst = out;
50 |
51 | v = 0;
52 | for (i = 0; in[i] && in[i] != '='; i++) {
53 | unsigned int index= in[i]-43;
54 | if (index>=SIZEOF_ARRAY(map2) || map2[index] == 0xff)
55 | return -1;
56 | v = (v << 6) + map2[index];
57 | if (i & 3) {
58 | if (dst - out < out_size) {
59 | *dst++ = v >> (6 - 2 * (i & 3));
60 | }
61 | }
62 | }
63 |
64 | return dst - out;
65 | }
66 |
67 | /*****************************************************************************
68 | * b64_encode: Stolen from VLC's http.c.
69 | * Simplified by Michael.
70 | * Fixed edge cases and made it work from data (vs. strings) by Ryan.
71 | *****************************************************************************/
72 |
73 | char *base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
74 | {
75 | static const char b64[] =
76 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
77 | char *ret, *dst;
78 | unsigned i_bits = 0;
79 | int i_shift = 0;
80 | int bytes_remaining = in_size;
81 |
82 | if (in_size >= UINT_MAX / 4 ||
83 | out_size < BASE64_SIZE(in_size))
84 | return NULL;
85 | ret = dst = out;
86 | while (bytes_remaining) {
87 | i_bits = (i_bits << 8) + *in++;
88 | bytes_remaining--;
89 | i_shift += 8;
90 |
91 | do {
92 | *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
93 | i_shift -= 6;
94 | } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0));
95 | }
96 | while ((dst - ret) & 3)
97 | *dst++ = '=';
98 | *dst = '\0';
99 |
100 | return ret;
101 | }
102 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/base64.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef BASE64_H
22 | #define BASE64_H
23 |
24 | #include
25 |
26 | /**
27 | * Decode a base64-encoded string.
28 | *
29 | * @param out buffer for decoded data
30 | * @param in null-terminated input string
31 | * @param out_size size in bytes of the out buffer, must be at
32 | * least 3/4 of the length of in
33 | * @return number of bytes written, or a negative value in case of
34 | * invalid input
35 | */
36 | int base64_decode(uint8_t *out, const char *in, int out_size);
37 |
38 | /**
39 | * Encode data to base64 and null-terminate.
40 | *
41 | * @param out buffer for encoded data
42 | * @param out_size size in bytes of the output buffer, must be at
43 | * least BASE64_SIZE(in_size)
44 | * @param in_size size in bytes of the 'in' buffer
45 | * @return 'out' or NULL in case of error
46 | */
47 | char *base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
48 |
49 | /**
50 | * Calculate the output size needed to base64-encode x bytes.
51 | */
52 | #define BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)
53 |
54 | #endif /* BASE64_H */
55 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/config.h:
--------------------------------------------------------------------------------
1 | #define USE_IPTABLES
2 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/dnstc.h:
--------------------------------------------------------------------------------
1 | #ifndef DNSTC_H
2 | #define DNSTC_H
3 |
4 | typedef struct dnstc_config_t {
5 | struct sockaddr_in bindaddr;
6 | } dnstc_config;
7 |
8 | typedef struct dnstc_instance_t {
9 | list_head list;
10 | dnstc_config config;
11 | struct event listener;
12 | } dnstc_instance;
13 |
14 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
15 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
16 | #endif /* REDUDP_H */
17 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/http-auth.h:
--------------------------------------------------------------------------------
1 | #ifndef HTTP_AUTH_H
2 | #define HTTP_AUTH_H
3 |
4 | typedef struct http_auth_t {
5 | char *last_auth_query;
6 | int last_auth_count;
7 | } http_auth;
8 |
9 | /*
10 | * Create the authentication header contents for the `Basic' scheme.
11 | * This is done by encoding the string "USER:PASS" to base64 and
12 | * prepending the string "Basic " in front of it.
13 | *
14 | */
15 |
16 | char* basic_authentication_encode(const char *user, const char *passwd);
17 |
18 | /*
19 | * Create the authentication header contents for the 'Digest' scheme.
20 | * only md5 method is available, see RFC 2617 for detail.
21 | *
22 | */
23 | char* digest_authentication_encode(const char *line, const char *user, const char *passwd,
24 | const char *method, const char *path, int count, const char *cnonce);
25 |
26 | #endif /* HTTP_AUTH_H */
27 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/libc-compat.h:
--------------------------------------------------------------------------------
1 | #ifndef UUID_67C91670_FCCB_4855_BDF7_609F1EECB8B4
2 | #define UUID_67C91670_FCCB_4855_BDF7_609F1EECB8B4
3 |
4 | /* all these definitions, are included into bits/in.h from libc6-dev 2.15-0ubuntu10
5 | * from Ubuntu 12.04 and is not included into libc6-dev 2.11.1-0ubuntu7.10 from
6 | * Ubuntu 10.04.
7 | * linux/in.h is not included directly because of lots of redefinitions,
8 | * extracting single value from linux/in.h is not done because it looks like
9 | * autotools reinvention */
10 | #ifndef IP_ORIGDSTADDR
11 | # warning Using hardcoded value for IP_ORIGDSTADDR as libc headers do not define it.
12 | # define IP_ORIGDSTADDR 20
13 | #endif
14 |
15 | #ifndef IP_RECVORIGDSTADDR
16 | # warning Using hardcoded value for IP_RECVORIGDSTADDR as libc headers do not define it.
17 | # define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
18 | #endif
19 |
20 | #ifndef IP_TRANSPARENT
21 | # warning Using hardcoded value for IP_TRANSPARENT as libc headers do not define it.
22 | # define IP_TRANSPARENT 19
23 | #endif
24 |
25 | #endif // 67C91670_FCCB_4855_BDF7_609F1EECB8B4
26 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/libevent-compat.h:
--------------------------------------------------------------------------------
1 | #ifndef UUID_FC148CFA_5ECC_488E_8A62_CD39406C9F1E
2 | #define UUID_FC148CFA_5ECC_488E_8A62_CD39406C9F1E
3 |
4 | /* evutil_socket_t is macros in libevent-2.0, not typedef, libevent-1.4 is
5 | * still supported because of Ubuntu 10.04 LTS */
6 | #ifndef evutil_socket_t
7 | # warning Using hardcoded value for evutil_socket_t as libevent headers do not define it.
8 | # define evutil_socket_t int
9 | #endif
10 |
11 | #endif // FC148CFA_5ECC_488E_8A62_CD39406C9F1E
12 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/log.h:
--------------------------------------------------------------------------------
1 | #ifndef LOG_H_WED_JAN_24_18_21_27_2007
2 | #define LOG_H_WED_JAN_24_18_21_27_2007
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #define log_errno(prio, msg...) _log_write(__FILE__, __LINE__, __func__, 1, prio, ## msg)
9 | #define log_error(prio, msg...) _log_write(__FILE__, __LINE__, __func__, 0, prio, ## msg)
10 |
11 | int log_preopen(const char *dst, bool log_debug, bool log_info);
12 | void log_open();
13 |
14 | void _log_vwrite(const char *file, int line, const char *func, int do_errno, int priority, const char *fmt, va_list ap);
15 |
16 | void _log_write(const char *file, int line, const char *func, int do_errno, int priority, const char *fmt, ...)
17 | #if defined(__GNUC__)
18 | __attribute__ (( format (printf, 6, 7) ))
19 | #endif
20 | ;
21 |
22 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
23 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
24 | #endif /* LOG_H_WED_JAN_24_18_21_27_2007 */
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/main.h:
--------------------------------------------------------------------------------
1 | #ifndef MAIN_H_TUE_JAN_23_15_38_25_2007
2 | #define MAIN_H_TUE_JAN_23_15_38_25_2007
3 |
4 | #include "parser.h"
5 |
6 | typedef struct app_subsys_t {
7 | int (*init)();
8 | int (*fini)();
9 | parser_section* conf_section;
10 | } app_subsys;
11 |
12 | #define SIZEOF_ARRAY(arr) (sizeof(arr) / sizeof(arr[0]))
13 | #define FOREACH(ptr, array) for (ptr = array; ptr < array + SIZEOF_ARRAY(array); ptr++)
14 | #define FOREACH_REV(ptr, array) for (ptr = array + SIZEOF_ARRAY(array) - 1; ptr >= array; ptr--)
15 |
16 |
17 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
18 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
19 | #endif /* MAIN_H_TUE_JAN_23_15_38_25_2007 */
20 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/md5.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
3 |
4 | This software is provided 'as-is', without any express or implied
5 | warranty. In no event will the authors be held liable for any damages
6 | arising from the use of this software.
7 |
8 | Permission is granted to anyone to use this software for any purpose,
9 | including commercial applications, and to alter it and redistribute it
10 | freely, subject to the following restrictions:
11 |
12 | 1. The origin of this software must not be misrepresented; you must not
13 | claim that you wrote the original software. If you use this software
14 | in a product, an acknowledgment in the product documentation would be
15 | appreciated but is not required.
16 | 2. Altered source versions must be plainly marked as such, and must not be
17 | misrepresented as being the original software.
18 | 3. This notice may not be removed or altered from any source distribution.
19 |
20 | L. Peter Deutsch
21 | ghost@aladdin.com
22 |
23 | */
24 | /* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
25 | /*
26 | Independent implementation of MD5 (RFC 1321).
27 |
28 | This code implements the MD5 Algorithm defined in RFC 1321, whose
29 | text is available at
30 | http://www.ietf.org/rfc/rfc1321.txt
31 | The code is derived from the text of the RFC, including the test suite
32 | (section A.5) but excluding the rest of Appendix A. It does not include
33 | any code or documentation that is identified in the RFC as being
34 | copyrighted.
35 |
36 | The original and principal author of md5.h is L. Peter Deutsch
37 | . Other authors are noted in the change history
38 | that follows (in reverse chronological order):
39 |
40 | 2002-04-13 lpd Removed support for non-ANSI compilers; removed
41 | references to Ghostscript; clarified derivation from RFC 1321;
42 | now handles byte order either statically or dynamically.
43 | 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
44 | 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
45 | added conditionalization for C++ compilation from Martin
46 | Purschke .
47 | 1999-05-03 lpd Original version.
48 | */
49 |
50 | #ifndef md5_INCLUDED
51 | # define md5_INCLUDED
52 |
53 | /*
54 | * This package supports both compile-time and run-time determination of CPU
55 | * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
56 | * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
57 | * defined as non-zero, the code will be compiled to run only on big-endian
58 | * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
59 | * run on either big- or little-endian CPUs, but will run slightly less
60 | * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
61 | */
62 |
63 | typedef unsigned char md5_byte_t; /* 8-bit byte */
64 | typedef unsigned int md5_word_t; /* 32-bit word */
65 |
66 | /* Define the state of the MD5 Algorithm. */
67 | typedef struct md5_state_s {
68 | md5_word_t count[2]; /* message length in bits, lsw first */
69 | md5_word_t abcd[4]; /* digest buffer */
70 | md5_byte_t buf[64]; /* accumulate block */
71 | } md5_state_t;
72 |
73 | #ifdef __cplusplus
74 | extern "C"
75 | {
76 | #endif
77 |
78 | /* Initialize the algorithm. */
79 | void md5_init(md5_state_t *pms);
80 |
81 | /* Append a string to the message. */
82 | void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
83 |
84 | /* Finish the message and return the digest. */
85 | void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
86 |
87 | #ifdef __cplusplus
88 | } /* end extern "C" */
89 | #endif
90 |
91 | #endif /* md5_INCLUDED */
92 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/parser.h:
--------------------------------------------------------------------------------
1 | #ifndef PARSER_H_THU_JAN_11_04_49_38_2007
2 | #define PARSER_H_THU_JAN_11_04_49_38_2007
3 |
4 | #include
5 | #include
6 |
7 | typedef enum {
8 | pt_bool, // "bool" from stdbool.h, not "_Bool" or anything else
9 | pt_pchar,
10 | pt_uint16,
11 | pt_in_addr,
12 | pt_in_addr2, // inaddr[0] = net, inaddr[1] = netmask
13 | } parser_type;
14 |
15 | typedef struct parser_entry_t {
16 | const char *key;
17 | parser_type type;
18 | void *addr;
19 | } parser_entry;
20 |
21 |
22 | typedef struct parser_context_t parser_context;
23 |
24 |
25 | typedef struct parser_section_t parser_section;
26 | typedef int (*parser_section_onenter)(parser_section *section);
27 | typedef int (*parser_section_onexit)(parser_section *section);
28 |
29 | struct parser_section_t {
30 | parser_section *next;
31 | parser_context *context;
32 | const char *name;
33 | parser_section_onenter onenter; // is called on entry to section
34 | parser_section_onexit onexit; // is called on exit from section
35 | parser_entry *entries;
36 | void *data;
37 | };
38 |
39 |
40 |
41 | typedef void (*parser_errhandler)(const char *errmsg, int line);
42 |
43 | parser_context* parser_start(FILE *fd, parser_errhandler errhandler);
44 | void parser_add_section(parser_context *context, parser_section *section);
45 | int parser_run(parser_context *context);
46 | void parser_error(parser_context *context, const char *msg);
47 | void parser_stop(parser_context *context);
48 |
49 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
50 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
51 | #endif /* PARSER_H_THU_JAN_11_04_49_38_2007 */
52 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/reddns.c:
--------------------------------------------------------------------------------
1 | /* redsocks - transparent TCP-to-proxy redirector
2 | * Copyright (C) 2007-2011 Leonid Evdokimov
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy
6 | * of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include "parser.h"
21 | #include "main.h"
22 |
23 | typedef struct reddns_config_t reddns_config;
24 | struct reddns_config_t {
25 | struct sockaddr_in bindaddr;
26 | struct sockaddr_in relayaddr;
27 | struct in_addr fakenet;
28 | struct in_addr fakenetmask;
29 | };
30 |
31 | int reddns_onenter(parser_section *section)
32 | {
33 | reddns_config *conf = calloc(1, sizeof(reddns_config));
34 | section->data = conf;
35 | section->entries[0].addr = &conf->bindaddr.sin_port;
36 | section->entries[1].addr = &conf->fakenet;
37 | section->entries[2].addr = &conf->fakenetmask;
38 | section->entries[3].addr = &conf->relayaddr.sin_addr;
39 | section->entries[4].addr = &conf->relayaddr.sin_port;
40 | fprintf(stderr, "%s\n", __FUNCTION__);
41 | return 0;
42 | }
43 |
44 | int reddns_onexit(parser_section *section)
45 | {
46 | reddns_config *conf = section->data;
47 | fprintf(stderr,
48 | "%s {\n"
49 | "local_port = %u;\n"
50 | "fakeip_net = %s/%s;\n"
51 | "ip = %s;\n"
52 | "port = %u;\n"
53 | "}\n",
54 | __FUNCTION__,
55 | conf->bindaddr.sin_port,
56 | strdup(inet_ntoa(conf->fakenet)),
57 | strdup(inet_ntoa(conf->fakenetmask)),
58 | strdup(inet_ntoa(conf->relayaddr.sin_addr)),
59 | conf->relayaddr.sin_port
60 | );
61 | return 0;
62 | }
63 |
64 | parser_entry reddns_entries[] = {
65 | { .key = "local_port", .type = pt_uint16 },
66 | { .key = "fakeip_net", .type = pt_in_addr2 },
67 | { .key = "fakeip_netmask", .type = pt_in_addr },
68 | { .key = "ip", .type = pt_in_addr },
69 | { .key = "port", .type = pt_uint16 },
70 | { }
71 | };
72 |
73 | parser_section reddns_conf_section = {
74 | .name = "reddns",
75 | .entries = reddns_entries,
76 | .onenter = reddns_onenter,
77 | .onexit = reddns_onexit
78 | };
79 |
80 | int reddns_init() {
81 | #error It's non-working stub at the moment.
82 | return 0;
83 | }
84 |
85 | int reddns_fini() {
86 | return 0;
87 | }
88 |
89 | app_subsys reddns_subsys = {
90 | .init = reddns_init,
91 | .fini = reddns_fini,
92 | .conf_section = &reddns_conf_section,
93 | };
94 |
95 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
96 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
97 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/redsocks.h:
--------------------------------------------------------------------------------
1 | #ifndef REDSOCKS_H_WED_JAN_24_22_17_11_2007
2 | #define REDSOCKS_H_WED_JAN_24_22_17_11_2007
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "list.h"
8 |
9 |
10 | struct redsocks_client_t;
11 | struct redsocks_instance_t;
12 |
13 | typedef struct relay_subsys_t {
14 | char *name;
15 | size_t payload_len; // size of relay-specific data in client section
16 | size_t instance_payload_len; // size of relay-specify data in instance section
17 | evbuffercb readcb;
18 | evbuffercb writecb;
19 | void (*init)(struct redsocks_client_t *client);
20 | void (*fini)(struct redsocks_client_t *client);
21 | void (*instance_fini)(struct redsocks_instance_t *instance);
22 | // connect_relay (if any) is called instead of redsocks_connect_relay after client connection acceptance
23 | void (*connect_relay)(struct redsocks_client_t *client);
24 | } relay_subsys;
25 |
26 | typedef struct redsocks_config_t {
27 | struct sockaddr_in bindaddr;
28 | struct sockaddr_in relayaddr;
29 | char *type;
30 | char *login;
31 | char *password;
32 | uint16_t min_backoff_ms;
33 | uint16_t max_backoff_ms; // backoff capped by 65 seconds is enough :)
34 | uint16_t listenq;
35 | } redsocks_config;
36 |
37 | struct tracked_event {
38 | struct event ev;
39 | struct timeval inserted;
40 | };
41 |
42 | typedef struct redsocks_instance_t {
43 | list_head list;
44 | redsocks_config config;
45 | struct tracked_event listener;
46 | struct tracked_event accept_backoff;
47 | uint16_t accept_backoff_ms;
48 | list_head clients;
49 | relay_subsys *relay_ss;
50 | } redsocks_instance;
51 |
52 | typedef struct redsocks_client_t {
53 | list_head list;
54 | redsocks_instance *instance;
55 | struct bufferevent *client;
56 | struct bufferevent *relay;
57 | struct sockaddr_in clientaddr;
58 | struct sockaddr_in destaddr;
59 | int state; // it's used by bottom layer
60 | unsigned short client_evshut;
61 | unsigned short relay_evshut;
62 | time_t first_event;
63 | time_t last_event;
64 | } redsocks_client;
65 |
66 |
67 | void redsocks_drop_client(redsocks_client *client);
68 | void redsocks_touch_client(redsocks_client *client);
69 | void redsocks_connect_relay(redsocks_client *client);
70 | void redsocks_start_relay(redsocks_client *client);
71 |
72 | typedef int (*size_comparator)(size_t a, size_t b);
73 | int sizes_equal(size_t a, size_t b);
74 | int sizes_greater_equal(size_t a, size_t b);
75 | /** helper for functions when we expect ONLY reply of some size and anything else is error
76 | */
77 | int redsocks_read_expected(redsocks_client *client, struct evbuffer *input, void *data, size_comparator comparator, size_t expected);
78 |
79 | typedef struct evbuffer* (*redsocks_message_maker)(redsocks_client *client);
80 | typedef struct evbuffer* (*redsocks_message_maker_plain)(void *p);
81 | struct evbuffer *mkevbuffer(void *data, size_t len);
82 | /* Yahoo! This code is ex-plain! :-D */
83 | int redsocks_write_helper_ex_plain(
84 | struct bufferevent *buffev, redsocks_client *client,
85 | redsocks_message_maker_plain mkmessage, void *p, int state, size_t wm_low, size_t wm_high);
86 | int redsocks_write_helper_ex(
87 | struct bufferevent *buffev, redsocks_client *client,
88 | redsocks_message_maker mkmessage, int state, size_t wm_low, size_t wm_high);
89 | int redsocks_write_helper(
90 | struct bufferevent *buffev, redsocks_client *client,
91 | redsocks_message_maker mkmessage, int state, size_t wm_only);
92 |
93 |
94 | #define redsocks_close(fd) redsocks_close_internal((fd), __FILE__, __LINE__, __func__)
95 | void redsocks_close_internal(int fd, const char* file, int line, const char *func);
96 |
97 | #define redsocks_log_error(client, prio, msg...) \
98 | redsocks_log_write_plain(__FILE__, __LINE__, __func__, 0, &(client)->clientaddr, &(client)->destaddr, prio, ## msg)
99 | #define redsocks_log_errno(client, prio, msg...) \
100 | redsocks_log_write_plain(__FILE__, __LINE__, __func__, 1, &(client)->clientaddr, &(client)->destaddr, prio, ## msg)
101 | void redsocks_log_write_plain(
102 | const char *file, int line, const char *func, int do_errno,
103 | const struct sockaddr_in *clientaddr, const struct sockaddr_in *destaddr,
104 | int priority, const char *fmt, ...)
105 | #if defined(__GNUC__)
106 | __attribute__ (( format (printf, 8, 9) ))
107 | #endif
108 | ;
109 |
110 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
111 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
112 | #endif /* REDSOCKS_H_WED_JAN_24_22_17_11_2007 */
113 |
114 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/redudp.h:
--------------------------------------------------------------------------------
1 | #ifndef REDUDP_H
2 | #define REDUDP_H
3 |
4 | typedef struct redudp_config_t {
5 | struct sockaddr_in bindaddr;
6 | struct sockaddr_in relayaddr;
7 | // TODO: outgoingaddr;
8 | struct sockaddr_in destaddr;
9 | char *login;
10 | char *password;
11 | uint16_t max_pktqueue;
12 | uint16_t udp_timeout;
13 | uint16_t udp_timeout_stream;
14 | } redudp_config;
15 |
16 | typedef struct redudp_instance_t {
17 | list_head list;
18 | redudp_config config;
19 | struct event listener;
20 | list_head clients;
21 | } redudp_instance;
22 |
23 | typedef struct redudp_client_t {
24 | list_head list;
25 | redudp_instance *instance;
26 | struct sockaddr_in clientaddr;
27 | struct sockaddr_in destaddr;
28 | int sender_fd; // shared between several clients socket (bound to `destaddr`)
29 | struct event timeout;
30 | struct bufferevent *relay;
31 | struct event udprelay;
32 | struct sockaddr_in udprelayaddr;
33 | int state; // it's used by bottom layer
34 | time_t first_event;
35 | time_t last_client_event;
36 | time_t last_relay_event;
37 | unsigned int queue_len;
38 | list_head queue;
39 | } redudp_client;
40 |
41 | typedef struct enqueued_packet_t {
42 | list_head list;
43 | size_t len;
44 | char data[1];
45 | } enqueued_packet;
46 |
47 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
48 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
49 | #endif /* REDUDP_H */
50 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/socks4.c:
--------------------------------------------------------------------------------
1 | /* redsocks - transparent TCP-to-proxy redirector
2 | * Copyright (C) 2007-2011 Leonid Evdokimov
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy
6 | * of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include "log.h"
21 | #include "redsocks.h"
22 |
23 | typedef enum socks4_state_t {
24 | socks4_new,
25 | socks4_request_sent,
26 | socks4_reply_came,
27 | socks4_MAX,
28 | } socks4_state;
29 |
30 | typedef struct socks4_req_t {
31 | uint8_t ver;
32 | uint8_t cmd;
33 | uint16_t port;
34 | uint32_t addr;
35 | char login[1]; // we need at least zero-byte
36 | } PACKED socks4_req;
37 |
38 | const int socks4_ver = 4;
39 | const int socks4_cmd_connect = 1;
40 | const int socks4_cmd_bind = 2;
41 |
42 | typedef struct socks4_reply_t {
43 | uint8_t ver;
44 | uint8_t status;
45 | uint16_t port;
46 | uint32_t addr;
47 | } PACKED socks4_reply;
48 |
49 | const int socks4_status_ok = 90;
50 | const int socks4_status_fail = 91;
51 | const int socks4_status_no_ident = 92;
52 | const int socks4_status_fake_ident = 93;
53 |
54 |
55 | void socks4_client_init(redsocks_client *client)
56 | {
57 | if (client->instance->config.password)
58 | redsocks_log_error(client, LOG_WARNING, "password is ignored for socks4 connections");
59 |
60 | client->state = socks4_new;
61 | }
62 |
63 |
64 | static void socks4_read_cb(struct bufferevent *buffev, void *_arg)
65 | {
66 | redsocks_client *client = _arg;
67 |
68 | assert(client->state >= socks4_request_sent);
69 |
70 | redsocks_touch_client(client);
71 |
72 | if (client->state == socks4_request_sent) {
73 | socks4_reply reply;
74 |
75 | if (redsocks_read_expected(client, buffev->input, &reply, sizes_greater_equal, sizeof(reply)) < 0)
76 | return;
77 |
78 | client->state = socks4_reply_came;
79 | if (reply.ver != 0) {
80 | redsocks_log_error(client, LOG_NOTICE, "Socks4 server reported unexpected reply version...");
81 | redsocks_drop_client(client);
82 | }
83 | else if (reply.status == socks4_status_ok)
84 | redsocks_start_relay(client);
85 | else {
86 | redsocks_log_error(client, LOG_NOTICE, "Socks4 server status: %s (%i)",
87 | reply.status == socks4_status_fail ? "fail" :
88 | reply.status == socks4_status_no_ident ? "no ident" :
89 | reply.status == socks4_status_fake_ident ? "fake ident" : "?",
90 | reply.status);
91 | redsocks_drop_client(client);
92 | }
93 | }
94 | }
95 |
96 | static struct evbuffer *socks4_mkconnect(redsocks_client *client)
97 | {
98 | const redsocks_config *config = &client->instance->config;
99 | const char *username = config->login ? config->login : "";
100 | // space for \0 comes from socks4_req->login
101 | size_t username_len = strlen(username);
102 | size_t len = sizeof(socks4_req) + username_len;
103 | socks4_req *req = calloc(1, len);
104 |
105 | req->ver = socks4_ver;
106 | req->cmd = socks4_cmd_connect;
107 | req->port = client->destaddr.sin_port;
108 | req->addr = client->destaddr.sin_addr.s_addr;
109 | memcpy(req->login, username, username_len + 1);
110 |
111 | struct evbuffer *ret = mkevbuffer(req, len);
112 | free(req);
113 | return ret;
114 | }
115 |
116 | static void socks4_write_cb(struct bufferevent *buffev, void *_arg)
117 | {
118 | redsocks_client *client = _arg;
119 |
120 | redsocks_touch_client(client);
121 |
122 | if (client->state == socks4_new) {
123 | redsocks_write_helper(
124 | buffev, client,
125 | socks4_mkconnect, socks4_request_sent, sizeof(socks4_reply)
126 | );
127 | }
128 | else if (client->state >= socks4_request_sent) {
129 | bufferevent_disable(buffev, EV_WRITE);
130 | }
131 | }
132 |
133 |
134 | relay_subsys socks4_subsys =
135 | {
136 | .name = "socks4",
137 | .payload_len = 0,
138 | .instance_payload_len = 0,
139 | .readcb = socks4_read_cb,
140 | .writecb = socks4_write_cb,
141 | .init = socks4_client_init,
142 | };
143 |
144 |
145 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
146 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
147 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/socks5.h:
--------------------------------------------------------------------------------
1 | #ifndef SOCKS5_H
2 | #define SOCKS5_H
3 |
4 | #include
5 | #include "utils.h"
6 |
7 | typedef struct socks5_method_req_t {
8 | uint8_t ver;
9 | uint8_t num_methods;
10 | uint8_t methods[1]; // at least one
11 | } PACKED socks5_method_req;
12 |
13 | typedef struct socks5_method_reply_t {
14 | uint8_t ver;
15 | uint8_t method;
16 | } PACKED socks5_method_reply;
17 |
18 | static const int socks5_ver = 5;
19 |
20 | static const int socks5_auth_none = 0x00;
21 | static const int socks5_auth_gssapi = 0x01;
22 | static const int socks5_auth_password = 0x02;
23 | static const int socks5_auth_invalid = 0xFF;
24 |
25 | typedef struct socks5_auth_reply_t {
26 | uint8_t ver;
27 | uint8_t status;
28 | } PACKED socks5_auth_reply;
29 |
30 | static const int socks5_password_ver = 0x01;
31 | static const int socks5_password_passed = 0x00;
32 |
33 |
34 | typedef struct socks5_addr_ipv4_t {
35 | uint32_t addr;
36 | uint16_t port;
37 | } PACKED socks5_addr_ipv4;
38 |
39 | typedef struct socks5_addr_domain_t {
40 | uint8_t size;
41 | uint8_t more[1];
42 | /* uint16_t port; */
43 | } PACKED socks5_addr_domain;
44 |
45 | typedef struct socks5_addr_ipv6_t {
46 | uint8_t addr[16];
47 | uint16_t port;
48 | } PACKED socks5_addr_ipv6;
49 |
50 | typedef struct socks5_req_t {
51 | uint8_t ver;
52 | uint8_t cmd;
53 | uint8_t reserved;
54 | uint8_t addrtype;
55 | /* socks5_addr_* */
56 | } PACKED socks5_req;
57 |
58 | typedef struct socks5_reply_t {
59 | uint8_t ver;
60 | uint8_t status;
61 | uint8_t reserved;
62 | uint8_t addrtype;
63 | /* socks5_addr_* */
64 | } PACKED socks5_reply;
65 |
66 | typedef struct socks5_udp_preabmle_t {
67 | uint16_t reserved;
68 | uint8_t frag_no;
69 | uint8_t addrtype; /* 0x01 for IPv4 */
70 | /* socks5_addr_* */
71 | socks5_addr_ipv4 ip; /* I support only IPv4 at the moment */
72 | } PACKED socks5_udp_preabmle;
73 |
74 | static const int socks5_reply_maxlen = 512; // as domain name can't be longer than 256 bytes
75 | static const int socks5_addrtype_ipv4 = 1;
76 | static const int socks5_addrtype_domain = 3;
77 | static const int socks5_addrtype_ipv6 = 4;
78 | static const int socks5_status_succeeded = 0;
79 | static const int socks5_status_server_failure = 1;
80 | static const int socks5_status_connection_not_allowed_by_ruleset = 2;
81 | static const int socks5_status_Network_unreachable = 3;
82 | static const int socks5_status_Host_unreachable = 4;
83 | static const int socks5_status_Connection_refused = 5;
84 | static const int socks5_status_TTL_expired = 6;
85 | static const int socks5_status_Command_not_supported = 7;
86 | static const int socks5_status_Address_type_not_supported = 8;
87 |
88 |
89 | const char* socks5_status_to_str(int socks5_status);
90 | int socks5_is_valid_cred(const char *login, const char *password);
91 |
92 | struct evbuffer *socks5_mkmethods_plain(int do_password);
93 | struct evbuffer *socks5_mkpassword_plain(const char *login, const char *password);
94 | const char* socks5_is_known_auth_method(socks5_method_reply *reply, int do_password);
95 |
96 | static const int socks5_cmd_connect = 1;
97 | static const int socks5_cmd_bind = 2;
98 | static const int socks5_cmd_udp_associate = 3;
99 | struct evbuffer *socks5_mkcommand_plain(int socks5_cmd, const struct sockaddr_in *destaddr);
100 |
101 |
102 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
103 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
104 | #endif /* SOCKS5_H */
105 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef UTILS_H_SAT_FEB__2_02_24_05_2008
2 | #define UTILS_H_SAT_FEB__2_02_24_05_2008
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | struct sockaddr_in;
9 |
10 | #define SIZEOF_ARRAY(arr) (sizeof(arr) / sizeof(arr[0]))
11 | #define FOREACH(ptr, array) for (ptr = array; ptr < array + SIZEOF_ARRAY(array); ptr++)
12 | #define FOREACH_REV(ptr, array) for (ptr = array + SIZEOF_ARRAY(array) - 1; ptr >= array; ptr--)
13 |
14 | #define UNUSED(x) ((void)(x))
15 |
16 | #if defined __GNUC__
17 | #define PACKED __attribute__((packed))
18 | #else
19 | #error Unknown compiler, modify utils.h for it
20 | #endif
21 |
22 |
23 | /**
24 | * container_of - cast a member of a structure out to the containing structure
25 | * @ptr: the pointer to the member.
26 | * @type: the type of the container struct this is embedded in.
27 | * @member: the name of the member within the struct.
28 | *
29 | */
30 | #define container_of(ptr, type, member) ({ \
31 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \
32 | (type *)( (char *)__mptr - offsetof(type,member) );})
33 |
34 | #define clamp_value(value, min_val, max_val) do { \
35 | if (value < min_val) \
36 | value = min_val; \
37 | if (value > max_val) \
38 | value = max_val; \
39 | } while (0)
40 |
41 |
42 | time_t redsocks_time(time_t *t);
43 | char *redsocks_evbuffer_readline(struct evbuffer *buf);
44 | struct bufferevent* red_connect_relay(struct sockaddr_in *addr, evbuffercb writecb, everrorcb errorcb, void *cbarg);
45 | int red_socket_geterrno(struct bufferevent *buffev);
46 | int red_is_socket_connected_ok(struct bufferevent *buffev);
47 | int red_recv_udp_pkt(int fd, char *buf, size_t buflen, struct sockaddr_in *fromaddr, struct sockaddr_in *toaddr);
48 |
49 | int fcntl_nonblock(int fd);
50 |
51 | #define event_fmt_str "%s|%s|%s|%s|%s|0x%x"
52 | #define event_fmt(what) \
53 | (what) & EVBUFFER_READ ? "EVBUFFER_READ" : "0", \
54 | (what) & EVBUFFER_WRITE ? "EVBUFFER_WRITE" : "0", \
55 | (what) & EVBUFFER_EOF ? "EVBUFFER_EOF" : "0", \
56 | (what) & EVBUFFER_ERROR ? "EVBUFFER_ERROR" : "0", \
57 | (what) & EVBUFFER_TIMEOUT ? "EVBUFFER_TIMEOUT" : "0", \
58 | (what) & ~(EVBUFFER_READ|EVBUFFER_WRITE|EVBUFFER_EOF|EVBUFFER_ERROR|EVBUFFER_TIMEOUT)
59 |
60 | #if INET6_ADDRSTRLEN < INET_ADDRSTRLEN
61 | # error Impossible happens: INET6_ADDRSTRLEN < INET_ADDRSTRLEN
62 | #else
63 | # define RED_INET_ADDRSTRLEN (INET6_ADDRSTRLEN + 1 + 5 + 1) // addr + : + port + \0
64 | #endif
65 | char *red_inet_ntop(const struct sockaddr_in* sa, char* buffer, size_t buffer_size);
66 |
67 | /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
68 | /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
69 | #endif /* UTILS_H_SAT_FEB__2_02_24_05_2008 */
70 |
--------------------------------------------------------------------------------
/app/src/main/cpp/redsocks/version.h:
--------------------------------------------------------------------------------
1 | #ifndef VERSION_H_SUN_NOV_27_03_22_30_2011
2 | #define VERSION_H_SUN_NOV_27_03_22_30_2011
3 |
4 | const char* redsocks_version = "0.4";
5 |
6 | #endif // VERSION_H_SUN_NOV_27_03_22_30_2011
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/btr/proxy/selector/pac/PacScriptParser.java:
--------------------------------------------------------------------------------
1 | package com.btr.proxy.selector.pac;
2 |
3 | /***************************************************************************
4 | * Common interface for PAC script parsers.
5 | *
6 | * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
7 | ***************************************************************************/
8 | public interface PacScriptParser {
9 |
10 | /***************************************************************************
11 | * Gets the source of the PAC script used by this parser.
12 | *
13 | * @return a PacScriptSource.
14 | **************************************************************************/
15 | public PacScriptSource getScriptSource();
16 |
17 | /*************************************************************************
18 | * Evaluates the given URL and host against the PAC script.
19 | *
20 | * @param url
21 | * the URL to evaluate.
22 | * @param host
23 | * the host name part of the URL.
24 | * @return the script result.
25 | * @throws ProxyEvaluationException
26 | * on execution error.
27 | ************************************************************************/
28 | public String evaluate(String url, String host)
29 | throws ProxyEvaluationException;
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/btr/proxy/selector/pac/PacScriptSource.java:
--------------------------------------------------------------------------------
1 | package com.btr.proxy.selector.pac;
2 |
3 | import java.io.IOException;
4 |
5 | /*****************************************************************************
6 | * An source to fetch the PAC script from.
7 | *
8 | * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
9 | ****************************************************************************/
10 |
11 | public interface PacScriptSource {
12 |
13 | /*************************************************************************
14 | * Gets the PAC script content as String.
15 | *
16 | * @return a script.
17 | * @throws IOException
18 | * on read error.
19 | ************************************************************************/
20 |
21 | public String getScriptContent() throws IOException;
22 |
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/btr/proxy/selector/pac/Proxy.java:
--------------------------------------------------------------------------------
1 | package com.btr.proxy.selector.pac;
2 |
3 | public class Proxy {
4 |
5 | public final static Proxy NO_PROXY = new Proxy(null, 0, null);
6 |
7 | public final static String TYPE_HTTP = "http";
8 | public final static String TYPE_HTTPS = "https";
9 | public final static String TYPE_SOCKS4 = "socks4";
10 | public final static String TYPE_SOCKS5 = "socks5";
11 |
12 | public String type = "http";
13 | public String host = "";
14 | public int port = 3128;
15 |
16 | public Proxy(String host, int port, String type) {
17 | this.host = host;
18 | this.port = port;
19 | this.type = type;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/btr/proxy/selector/pac/ProxyEvaluationException.java:
--------------------------------------------------------------------------------
1 | package com.btr.proxy.selector.pac;
2 |
3 | /*****************************************************************************
4 | * Exception for PAC script errors.
5 | *
6 | * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
7 | ****************************************************************************/
8 |
9 | public class ProxyEvaluationException extends ProxyException {
10 |
11 | private static final long serialVersionUID = 1L;
12 |
13 | /*************************************************************************
14 | * Constructor
15 | ************************************************************************/
16 |
17 | public ProxyEvaluationException() {
18 | super();
19 | }
20 |
21 | /*************************************************************************
22 | * Constructor
23 | *
24 | * @param message
25 | * the error message.
26 | * @param cause
27 | * the causing exception for exception chaining.
28 | ************************************************************************/
29 |
30 | public ProxyEvaluationException(String message, Throwable cause) {
31 | super(message, cause);
32 | }
33 |
34 | /*************************************************************************
35 | * Constructor
36 | *
37 | * @param message
38 | * the error message.
39 | ************************************************************************/
40 |
41 | public ProxyEvaluationException(String message) {
42 | super(message);
43 | }
44 |
45 | /*************************************************************************
46 | * Constructor
47 | *
48 | * @param cause
49 | * the causing exception for exception chaining.
50 | ************************************************************************/
51 |
52 | public ProxyEvaluationException(Throwable cause) {
53 | super(cause);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/btr/proxy/selector/pac/ProxyException.java:
--------------------------------------------------------------------------------
1 | package com.btr.proxy.selector.pac;
2 |
3 | /*****************************************************************************
4 | * Indicates an exception in the proxy framework.
5 | *
6 | * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
7 | ****************************************************************************/
8 |
9 | public class ProxyException extends Exception {
10 |
11 | private static final long serialVersionUID = 1L;
12 |
13 | /*************************************************************************
14 | * Constructor
15 | ************************************************************************/
16 |
17 | public ProxyException() {
18 | super();
19 | }
20 |
21 | /*************************************************************************
22 | * Constructor
23 | *
24 | * @param message
25 | * the error message
26 | * @param cause
27 | * the causing exception for chaining exceptions.
28 | ************************************************************************/
29 |
30 | public ProxyException(String message, Throwable cause) {
31 | super(message, cause);
32 | }
33 |
34 | /*************************************************************************
35 | * Constructor
36 | *
37 | * @param message
38 | * the error message
39 | ************************************************************************/
40 |
41 | public ProxyException(String message) {
42 | super(message);
43 | }
44 |
45 | /*************************************************************************
46 | * Constructor
47 | *
48 | * @param cause
49 | * the causing exception for chaining exceptions.
50 | ************************************************************************/
51 |
52 | public ProxyException(Throwable cause) {
53 | super(cause);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ksmaze/android/preference/ListPreferenceMultiSelect.java:
--------------------------------------------------------------------------------
1 | /* proxydroid - Global / Individual Proxy App for Android
2 | * Copyright (C) 2011 K's Maze
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | *
17 | */
18 |
19 | package com.ksmaze.android.preference;
20 |
21 | import android.app.AlertDialog.Builder;
22 | import android.content.Context;
23 | import android.content.DialogInterface;
24 | import android.preference.ListPreference;
25 | import android.preference.Preference;
26 | import android.util.AttributeSet;
27 |
28 | /**
29 | * A {@link Preference} that displays a list of entries as a dialog and allows
30 | * multiple selections
31 | *
32 | * This preference will store a string into the SharedPreferences. This string
33 | * will be the values selected from the {@link #setEntryValues(CharSequence[])}
34 | * array.
35 | *
36 | */
37 | public class ListPreferenceMultiSelect extends ListPreference {
38 | // Need to make sure the SEPARATOR is unique and weird enough that it
39 | // doesn't match one of the entries.
40 | // Not using any fancy symbols because this is interpreted as a regex for
41 | // splitting strings.
42 | private static final String SEPARATOR = " , ";
43 |
44 | private boolean[] mClickedDialogEntryIndices;
45 |
46 | public ListPreferenceMultiSelect(Context context, AttributeSet attrs) {
47 | super(context, attrs);
48 |
49 | mClickedDialogEntryIndices = new boolean[getEntries().length];
50 | }
51 |
52 | @Override
53 | public void setEntries(CharSequence[] entries) {
54 | super.setEntries(entries);
55 | mClickedDialogEntryIndices = new boolean[entries.length];
56 | }
57 |
58 | public ListPreferenceMultiSelect(Context context) {
59 | this(context, null);
60 | }
61 |
62 | @Override
63 | protected void onPrepareDialogBuilder(Builder builder) {
64 | CharSequence[] entries = getEntries();
65 | CharSequence[] entryValues = getEntryValues();
66 |
67 | if (entries == null || entryValues == null
68 | || entries.length != entryValues.length) {
69 | throw new IllegalStateException(
70 | "ListPreference requires an entries array and an entryValues array which are both the same length");
71 | }
72 |
73 | restoreCheckedEntries();
74 | builder.setMultiChoiceItems(entries, mClickedDialogEntryIndices,
75 | new DialogInterface.OnMultiChoiceClickListener() {
76 | @Override
77 | public void onClick(DialogInterface dialog, int which,
78 | boolean val) {
79 | mClickedDialogEntryIndices[which] = val;
80 | }
81 | });
82 | }
83 |
84 | public static String[] parseStoredValue(CharSequence val) {
85 | if (val == null)
86 | return null;
87 | if ("".equals(val))
88 | return null;
89 | else
90 | return ((String) val).split(SEPARATOR);
91 | }
92 |
93 | private void restoreCheckedEntries() {
94 | CharSequence[] entryValues = getEntryValues();
95 |
96 | String[] vals = parseStoredValue(getValue());
97 | if (vals != null) {
98 | for (String val1 : vals) {
99 | String val = val1.trim();
100 | for (int i = 0; i < entryValues.length; i++) {
101 | CharSequence entry = entryValues[i];
102 | if (entry.equals(val)) {
103 | mClickedDialogEntryIndices[i] = true;
104 | break;
105 | }
106 | }
107 | }
108 | }
109 | }
110 |
111 | @Override
112 | protected void onDialogClosed(boolean positiveResult) {
113 | // super.onDialogClosed(positiveResult);
114 |
115 | CharSequence[] entryValues = getEntryValues();
116 | if (positiveResult && entryValues != null) {
117 | StringBuffer value = new StringBuffer();
118 | for (int i = 0; i < entryValues.length; i++) {
119 | if (mClickedDialogEntryIndices[i]) {
120 | value.append(entryValues[i]).append(SEPARATOR);
121 | }
122 | }
123 |
124 | if (callChangeListener(value)) {
125 | String val = value.toString();
126 | if (val.length() > 0)
127 | val = val.substring(0, val.length() - SEPARATOR.length());
128 | setValue(val);
129 | }
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/app/src/main/java/org/proxydroid/Exec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.proxydroid;
18 |
19 | import java.io.FileDescriptor;
20 |
21 | /**
22 | * Utility methods for creating and managing a subprocess.
23 | *
24 | * Note: The native methods access a package-private java.io.FileDescriptor
25 | * field to get and set the raw Linux file descriptor. This might break if the
26 | * implementation of java.io.FileDescriptor is changed.
27 | */
28 |
29 | public class Exec {
30 | static {
31 | java.lang.System.loadLibrary("exec");
32 | }
33 |
34 | /**
35 | * Close a given file descriptor.
36 | */
37 | public static native void close(FileDescriptor fd);
38 |
39 | /**
40 | * Create a subprocess. Differs from java.lang.ProcessBuilder in that a pty
41 | * is used to communicate with the subprocess.
42 | *
43 | * Callers are responsible for calling Exec.close() on the returned file
44 | * descriptor.
45 | *
46 | * @param rdt Whether redirect stdout and stderr
47 | * @param cmd The command to execute.
48 | * @param args An array of arguments to the command.
49 | * @param envVars An array of strings of the form "VAR=value" to be added to the
50 | * environment of the process.
51 | * @param scripts The scripts to execute.
52 | * @param processId A one-element array to which the process ID of the started
53 | * process will be written.
54 | * @return File descriptor
55 | */
56 | public static native FileDescriptor createSubprocess(int rdt, String cmd,
57 | String[] args, String[] envVars,
58 | String scripts, int[] processId);
59 |
60 | /**
61 | * Send SIGHUP to a process group.
62 | */
63 | public static native void hangupProcessGroup(int processId);
64 |
65 | /**
66 | * Causes the calling thread to wait for the process associated with the
67 | * receiver to finish executing.
68 | *
69 | * @return The exit value of the Process being waited on
70 | */
71 | public static native int waitFor(int processId);
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/org/proxydroid/FileArrayAdapter.java:
--------------------------------------------------------------------------------
1 | package org.proxydroid;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.TextView;
9 |
10 | import org.proxydroid.utils.Option;
11 |
12 | import java.util.List;
13 |
14 | public class FileArrayAdapter extends ArrayAdapter