├── .github
└── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── openssl-nginx-cross-compile-error.md
├── NginxDemo
├── .gitignore
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── zhangtom
│ │ │ └── nginxdemo
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── assets
│ │ │ └── nginx
│ │ │ │ ├── conf
│ │ │ │ ├── fastcgi.conf
│ │ │ │ ├── fastcgi.conf.default
│ │ │ │ ├── fastcgi_params
│ │ │ │ ├── fastcgi_params.default
│ │ │ │ ├── koi-utf
│ │ │ │ ├── koi-win
│ │ │ │ ├── mime.types
│ │ │ │ ├── mime.types.default
│ │ │ │ ├── nginx.conf
│ │ │ │ ├── nginx.conf.default
│ │ │ │ ├── scgi_params
│ │ │ │ ├── scgi_params.default
│ │ │ │ ├── uwsgi_params
│ │ │ │ ├── uwsgi_params.default
│ │ │ │ └── win-utf
│ │ │ │ ├── html
│ │ │ │ ├── 50x.html
│ │ │ │ └── index.html
│ │ │ │ └── sbin
│ │ │ │ └── nginx
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zhangtom
│ │ │ │ └── nginxdemo
│ │ │ │ └── MainActivity.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ └── activity_main.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
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── zhangtom
│ │ └── nginxdemo
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
├── Setenv-android.sh
├── glob
├── glob.c
└── glob.h
├── make_nginx.sh
├── make_openssl.sh
└── portable_cmds.sh
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9 |
10 | **Describe the solution you'd like**
11 | A clear and concise description of what you want to happen.
12 |
13 | **Describe alternatives you've considered**
14 | A clear and concise description of any alternative solutions or features you've considered.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/openssl-nginx-cross-compile-error.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: OpenSSL/Nginx cross compile error
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Info**
8 | OS & Version:
9 | Android NDK Version:
10 | Nginx Version:
11 | OpenSSL Version:
12 | OpenSSL FIPS Version(if any):
13 |
14 | **Describe the error**
15 | A clear and concise description of what the error is.
16 |
17 | **Log**
18 | Paste error messages in `make_openssl.log` or `make_nginx.log` about the error.
19 |
--------------------------------------------------------------------------------
/NginxDemo/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 | .idea/modules.xml
45 |
46 | # Keystore files
47 | # Uncomment the following line if you do not want to check your keystore files in.
48 | #*.jks
49 |
50 | # External native build folder generated in Android Studio 2.2 and later
51 | .externalNativeBuild
52 |
53 | # Google Services (e.g. APIs or Firebase)
54 | google-services.json
55 |
56 | # Freeline
57 | freeline.py
58 | freeline/
59 | freeline_project_description.json
60 |
61 | # fastlane
62 | fastlane/report.xml
63 | fastlane/Preview.html
64 | fastlane/screenshots
65 | fastlane/test_output
66 | fastlane/readme.md
67 |
68 | .DS_Store
--------------------------------------------------------------------------------
/NginxDemo/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/NginxDemo/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.zhangtom.nginxdemo"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25 | implementation 'com.jrummyapps:android-shell:1.0.0'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
29 | }
30 |
--------------------------------------------------------------------------------
/NginxDemo/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 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/androidTest/java/com/zhangtom/nginxdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zhangtom.nginxdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zhangtom.nginxdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/fastcgi.conf:
--------------------------------------------------------------------------------
1 |
2 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3 | fastcgi_param QUERY_STRING $query_string;
4 | fastcgi_param REQUEST_METHOD $request_method;
5 | fastcgi_param CONTENT_TYPE $content_type;
6 | fastcgi_param CONTENT_LENGTH $content_length;
7 |
8 | fastcgi_param SCRIPT_NAME $fastcgi_script_name;
9 | fastcgi_param REQUEST_URI $request_uri;
10 | fastcgi_param DOCUMENT_URI $document_uri;
11 | fastcgi_param DOCUMENT_ROOT $document_root;
12 | fastcgi_param SERVER_PROTOCOL $server_protocol;
13 | fastcgi_param REQUEST_SCHEME $scheme;
14 | fastcgi_param HTTPS $https if_not_empty;
15 |
16 | fastcgi_param GATEWAY_INTERFACE CGI/1.1;
17 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
18 |
19 | fastcgi_param REMOTE_ADDR $remote_addr;
20 | fastcgi_param REMOTE_PORT $remote_port;
21 | fastcgi_param SERVER_ADDR $server_addr;
22 | fastcgi_param SERVER_PORT $server_port;
23 | fastcgi_param SERVER_NAME $server_name;
24 |
25 | # PHP only, required if PHP was built with --enable-force-cgi-redirect
26 | fastcgi_param REDIRECT_STATUS 200;
27 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/fastcgi.conf.default:
--------------------------------------------------------------------------------
1 |
2 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3 | fastcgi_param QUERY_STRING $query_string;
4 | fastcgi_param REQUEST_METHOD $request_method;
5 | fastcgi_param CONTENT_TYPE $content_type;
6 | fastcgi_param CONTENT_LENGTH $content_length;
7 |
8 | fastcgi_param SCRIPT_NAME $fastcgi_script_name;
9 | fastcgi_param REQUEST_URI $request_uri;
10 | fastcgi_param DOCUMENT_URI $document_uri;
11 | fastcgi_param DOCUMENT_ROOT $document_root;
12 | fastcgi_param SERVER_PROTOCOL $server_protocol;
13 | fastcgi_param REQUEST_SCHEME $scheme;
14 | fastcgi_param HTTPS $https if_not_empty;
15 |
16 | fastcgi_param GATEWAY_INTERFACE CGI/1.1;
17 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
18 |
19 | fastcgi_param REMOTE_ADDR $remote_addr;
20 | fastcgi_param REMOTE_PORT $remote_port;
21 | fastcgi_param SERVER_ADDR $server_addr;
22 | fastcgi_param SERVER_PORT $server_port;
23 | fastcgi_param SERVER_NAME $server_name;
24 |
25 | # PHP only, required if PHP was built with --enable-force-cgi-redirect
26 | fastcgi_param REDIRECT_STATUS 200;
27 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/fastcgi_params:
--------------------------------------------------------------------------------
1 |
2 | fastcgi_param QUERY_STRING $query_string;
3 | fastcgi_param REQUEST_METHOD $request_method;
4 | fastcgi_param CONTENT_TYPE $content_type;
5 | fastcgi_param CONTENT_LENGTH $content_length;
6 |
7 | fastcgi_param SCRIPT_NAME $fastcgi_script_name;
8 | fastcgi_param REQUEST_URI $request_uri;
9 | fastcgi_param DOCUMENT_URI $document_uri;
10 | fastcgi_param DOCUMENT_ROOT $document_root;
11 | fastcgi_param SERVER_PROTOCOL $server_protocol;
12 | fastcgi_param REQUEST_SCHEME $scheme;
13 | fastcgi_param HTTPS $https if_not_empty;
14 |
15 | fastcgi_param GATEWAY_INTERFACE CGI/1.1;
16 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
17 |
18 | fastcgi_param REMOTE_ADDR $remote_addr;
19 | fastcgi_param REMOTE_PORT $remote_port;
20 | fastcgi_param SERVER_ADDR $server_addr;
21 | fastcgi_param SERVER_PORT $server_port;
22 | fastcgi_param SERVER_NAME $server_name;
23 |
24 | # PHP only, required if PHP was built with --enable-force-cgi-redirect
25 | fastcgi_param REDIRECT_STATUS 200;
26 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/fastcgi_params.default:
--------------------------------------------------------------------------------
1 |
2 | fastcgi_param QUERY_STRING $query_string;
3 | fastcgi_param REQUEST_METHOD $request_method;
4 | fastcgi_param CONTENT_TYPE $content_type;
5 | fastcgi_param CONTENT_LENGTH $content_length;
6 |
7 | fastcgi_param SCRIPT_NAME $fastcgi_script_name;
8 | fastcgi_param REQUEST_URI $request_uri;
9 | fastcgi_param DOCUMENT_URI $document_uri;
10 | fastcgi_param DOCUMENT_ROOT $document_root;
11 | fastcgi_param SERVER_PROTOCOL $server_protocol;
12 | fastcgi_param REQUEST_SCHEME $scheme;
13 | fastcgi_param HTTPS $https if_not_empty;
14 |
15 | fastcgi_param GATEWAY_INTERFACE CGI/1.1;
16 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
17 |
18 | fastcgi_param REMOTE_ADDR $remote_addr;
19 | fastcgi_param REMOTE_PORT $remote_port;
20 | fastcgi_param SERVER_ADDR $server_addr;
21 | fastcgi_param SERVER_PORT $server_port;
22 | fastcgi_param SERVER_NAME $server_name;
23 |
24 | # PHP only, required if PHP was built with --enable-force-cgi-redirect
25 | fastcgi_param REDIRECT_STATUS 200;
26 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/koi-utf:
--------------------------------------------------------------------------------
1 |
2 | # This map is not a full koi8-r <> utf8 map: it does not contain
3 | # box-drawing and some other characters. Besides this map contains
4 | # several koi8-u and Byelorussian letters which are not in koi8-r.
5 | # If you need a full and standard map, use contrib/unicode2nginx/koi-utf
6 | # map instead.
7 |
8 | charset_map koi8-r utf-8 {
9 |
10 | 80 E282AC ; # euro
11 |
12 | 95 E280A2 ; # bullet
13 |
14 | 9A C2A0 ; #
15 |
16 | 9E C2B7 ; # ·
17 |
18 | A3 D191 ; # small yo
19 | A4 D194 ; # small Ukrainian ye
20 |
21 | A6 D196 ; # small Ukrainian i
22 | A7 D197 ; # small Ukrainian yi
23 |
24 | AD D291 ; # small Ukrainian soft g
25 | AE D19E ; # small Byelorussian short u
26 |
27 | B0 C2B0 ; # °
28 |
29 | B3 D081 ; # capital YO
30 | B4 D084 ; # capital Ukrainian YE
31 |
32 | B6 D086 ; # capital Ukrainian I
33 | B7 D087 ; # capital Ukrainian YI
34 |
35 | B9 E28496 ; # numero sign
36 |
37 | BD D290 ; # capital Ukrainian soft G
38 | BE D18E ; # capital Byelorussian short U
39 |
40 | BF C2A9 ; # (C)
41 |
42 | C0 D18E ; # small yu
43 | C1 D0B0 ; # small a
44 | C2 D0B1 ; # small b
45 | C3 D186 ; # small ts
46 | C4 D0B4 ; # small d
47 | C5 D0B5 ; # small ye
48 | C6 D184 ; # small f
49 | C7 D0B3 ; # small g
50 | C8 D185 ; # small kh
51 | C9 D0B8 ; # small i
52 | CA D0B9 ; # small j
53 | CB D0BA ; # small k
54 | CC D0BB ; # small l
55 | CD D0BC ; # small m
56 | CE D0BD ; # small n
57 | CF D0BE ; # small o
58 |
59 | D0 D0BF ; # small p
60 | D1 D18F ; # small ya
61 | D2 D180 ; # small r
62 | D3 D181 ; # small s
63 | D4 D182 ; # small t
64 | D5 D183 ; # small u
65 | D6 D0B6 ; # small zh
66 | D7 D0B2 ; # small v
67 | D8 D18C ; # small soft sign
68 | D9 D18B ; # small y
69 | DA D0B7 ; # small z
70 | DB D188 ; # small sh
71 | DC D18D ; # small e
72 | DD D189 ; # small shch
73 | DE D187 ; # small ch
74 | DF D18A ; # small hard sign
75 |
76 | E0 D0AE ; # capital YU
77 | E1 D090 ; # capital A
78 | E2 D091 ; # capital B
79 | E3 D0A6 ; # capital TS
80 | E4 D094 ; # capital D
81 | E5 D095 ; # capital YE
82 | E6 D0A4 ; # capital F
83 | E7 D093 ; # capital G
84 | E8 D0A5 ; # capital KH
85 | E9 D098 ; # capital I
86 | EA D099 ; # capital J
87 | EB D09A ; # capital K
88 | EC D09B ; # capital L
89 | ED D09C ; # capital M
90 | EE D09D ; # capital N
91 | EF D09E ; # capital O
92 |
93 | F0 D09F ; # capital P
94 | F1 D0AF ; # capital YA
95 | F2 D0A0 ; # capital R
96 | F3 D0A1 ; # capital S
97 | F4 D0A2 ; # capital T
98 | F5 D0A3 ; # capital U
99 | F6 D096 ; # capital ZH
100 | F7 D092 ; # capital V
101 | F8 D0AC ; # capital soft sign
102 | F9 D0AB ; # capital Y
103 | FA D097 ; # capital Z
104 | FB D0A8 ; # capital SH
105 | FC D0AD ; # capital E
106 | FD D0A9 ; # capital SHCH
107 | FE D0A7 ; # capital CH
108 | FF D0AA ; # capital hard sign
109 | }
110 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/koi-win:
--------------------------------------------------------------------------------
1 |
2 | charset_map koi8-r windows-1251 {
3 |
4 | 80 88 ; # euro
5 |
6 | 95 95 ; # bullet
7 |
8 | 9A A0 ; #
9 |
10 | 9E B7 ; # ·
11 |
12 | A3 B8 ; # small yo
13 | A4 BA ; # small Ukrainian ye
14 |
15 | A6 B3 ; # small Ukrainian i
16 | A7 BF ; # small Ukrainian yi
17 |
18 | AD B4 ; # small Ukrainian soft g
19 | AE A2 ; # small Byelorussian short u
20 |
21 | B0 B0 ; # °
22 |
23 | B3 A8 ; # capital YO
24 | B4 AA ; # capital Ukrainian YE
25 |
26 | B6 B2 ; # capital Ukrainian I
27 | B7 AF ; # capital Ukrainian YI
28 |
29 | B9 B9 ; # numero sign
30 |
31 | BD A5 ; # capital Ukrainian soft G
32 | BE A1 ; # capital Byelorussian short U
33 |
34 | BF A9 ; # (C)
35 |
36 | C0 FE ; # small yu
37 | C1 E0 ; # small a
38 | C2 E1 ; # small b
39 | C3 F6 ; # small ts
40 | C4 E4 ; # small d
41 | C5 E5 ; # small ye
42 | C6 F4 ; # small f
43 | C7 E3 ; # small g
44 | C8 F5 ; # small kh
45 | C9 E8 ; # small i
46 | CA E9 ; # small j
47 | CB EA ; # small k
48 | CC EB ; # small l
49 | CD EC ; # small m
50 | CE ED ; # small n
51 | CF EE ; # small o
52 |
53 | D0 EF ; # small p
54 | D1 FF ; # small ya
55 | D2 F0 ; # small r
56 | D3 F1 ; # small s
57 | D4 F2 ; # small t
58 | D5 F3 ; # small u
59 | D6 E6 ; # small zh
60 | D7 E2 ; # small v
61 | D8 FC ; # small soft sign
62 | D9 FB ; # small y
63 | DA E7 ; # small z
64 | DB F8 ; # small sh
65 | DC FD ; # small e
66 | DD F9 ; # small shch
67 | DE F7 ; # small ch
68 | DF FA ; # small hard sign
69 |
70 | E0 DE ; # capital YU
71 | E1 C0 ; # capital A
72 | E2 C1 ; # capital B
73 | E3 D6 ; # capital TS
74 | E4 C4 ; # capital D
75 | E5 C5 ; # capital YE
76 | E6 D4 ; # capital F
77 | E7 C3 ; # capital G
78 | E8 D5 ; # capital KH
79 | E9 C8 ; # capital I
80 | EA C9 ; # capital J
81 | EB CA ; # capital K
82 | EC CB ; # capital L
83 | ED CC ; # capital M
84 | EE CD ; # capital N
85 | EF CE ; # capital O
86 |
87 | F0 CF ; # capital P
88 | F1 DF ; # capital YA
89 | F2 D0 ; # capital R
90 | F3 D1 ; # capital S
91 | F4 D2 ; # capital T
92 | F5 D3 ; # capital U
93 | F6 C6 ; # capital ZH
94 | F7 C2 ; # capital V
95 | F8 DC ; # capital soft sign
96 | F9 DB ; # capital Y
97 | FA C7 ; # capital Z
98 | FB D8 ; # capital SH
99 | FC DD ; # capital E
100 | FD D9 ; # capital SHCH
101 | FE D7 ; # capital CH
102 | FF DA ; # capital hard sign
103 | }
104 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/mime.types:
--------------------------------------------------------------------------------
1 |
2 | types {
3 | text/html html htm shtml;
4 | text/css css;
5 | text/xml xml;
6 | image/gif gif;
7 | image/jpeg jpeg jpg;
8 | application/javascript js;
9 | application/atom+xml atom;
10 | application/rss+xml rss;
11 |
12 | text/mathml mml;
13 | text/plain txt;
14 | text/vnd.sun.j2me.app-descriptor jad;
15 | text/vnd.wap.wml wml;
16 | text/x-component htc;
17 |
18 | image/png png;
19 | image/svg+xml svg svgz;
20 | image/tiff tif tiff;
21 | image/vnd.wap.wbmp wbmp;
22 | image/webp webp;
23 | image/x-icon ico;
24 | image/x-jng jng;
25 | image/x-ms-bmp bmp;
26 |
27 | application/font-woff woff;
28 | application/java-archive jar war ear;
29 | application/json json;
30 | application/mac-binhex40 hqx;
31 | application/msword doc;
32 | application/pdf pdf;
33 | application/postscript ps eps ai;
34 | application/rtf rtf;
35 | application/vnd.apple.mpegurl m3u8;
36 | application/vnd.google-earth.kml+xml kml;
37 | application/vnd.google-earth.kmz kmz;
38 | application/vnd.ms-excel xls;
39 | application/vnd.ms-fontobject eot;
40 | application/vnd.ms-powerpoint ppt;
41 | application/vnd.oasis.opendocument.graphics odg;
42 | application/vnd.oasis.opendocument.presentation odp;
43 | application/vnd.oasis.opendocument.spreadsheet ods;
44 | application/vnd.oasis.opendocument.text odt;
45 | application/vnd.openxmlformats-officedocument.presentationml.presentation
46 | pptx;
47 | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
48 | xlsx;
49 | application/vnd.openxmlformats-officedocument.wordprocessingml.document
50 | docx;
51 | application/vnd.wap.wmlc wmlc;
52 | application/x-7z-compressed 7z;
53 | application/x-cocoa cco;
54 | application/x-java-archive-diff jardiff;
55 | application/x-java-jnlp-file jnlp;
56 | application/x-makeself run;
57 | application/x-perl pl pm;
58 | application/x-pilot prc pdb;
59 | application/x-rar-compressed rar;
60 | application/x-redhat-package-manager rpm;
61 | application/x-sea sea;
62 | application/x-shockwave-flash swf;
63 | application/x-stuffit sit;
64 | application/x-tcl tcl tk;
65 | application/x-x509-ca-cert der pem crt;
66 | application/x-xpinstall xpi;
67 | application/xhtml+xml xhtml;
68 | application/xspf+xml xspf;
69 | application/zip zip;
70 |
71 | application/octet-stream bin exe dll;
72 | application/octet-stream deb;
73 | application/octet-stream dmg;
74 | application/octet-stream iso img;
75 | application/octet-stream msi msp msm;
76 |
77 | audio/midi mid midi kar;
78 | audio/mpeg mp3;
79 | audio/ogg ogg;
80 | audio/x-m4a m4a;
81 | audio/x-realaudio ra;
82 |
83 | video/3gpp 3gpp 3gp;
84 | video/mp2t ts;
85 | video/mp4 mp4;
86 | video/mpeg mpeg mpg;
87 | video/quicktime mov;
88 | video/webm webm;
89 | video/x-flv flv;
90 | video/x-m4v m4v;
91 | video/x-mng mng;
92 | video/x-ms-asf asx asf;
93 | video/x-ms-wmv wmv;
94 | video/x-msvideo avi;
95 | }
96 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/mime.types.default:
--------------------------------------------------------------------------------
1 |
2 | types {
3 | text/html html htm shtml;
4 | text/css css;
5 | text/xml xml;
6 | image/gif gif;
7 | image/jpeg jpeg jpg;
8 | application/javascript js;
9 | application/atom+xml atom;
10 | application/rss+xml rss;
11 |
12 | text/mathml mml;
13 | text/plain txt;
14 | text/vnd.sun.j2me.app-descriptor jad;
15 | text/vnd.wap.wml wml;
16 | text/x-component htc;
17 |
18 | image/png png;
19 | image/svg+xml svg svgz;
20 | image/tiff tif tiff;
21 | image/vnd.wap.wbmp wbmp;
22 | image/webp webp;
23 | image/x-icon ico;
24 | image/x-jng jng;
25 | image/x-ms-bmp bmp;
26 |
27 | application/font-woff woff;
28 | application/java-archive jar war ear;
29 | application/json json;
30 | application/mac-binhex40 hqx;
31 | application/msword doc;
32 | application/pdf pdf;
33 | application/postscript ps eps ai;
34 | application/rtf rtf;
35 | application/vnd.apple.mpegurl m3u8;
36 | application/vnd.google-earth.kml+xml kml;
37 | application/vnd.google-earth.kmz kmz;
38 | application/vnd.ms-excel xls;
39 | application/vnd.ms-fontobject eot;
40 | application/vnd.ms-powerpoint ppt;
41 | application/vnd.oasis.opendocument.graphics odg;
42 | application/vnd.oasis.opendocument.presentation odp;
43 | application/vnd.oasis.opendocument.spreadsheet ods;
44 | application/vnd.oasis.opendocument.text odt;
45 | application/vnd.openxmlformats-officedocument.presentationml.presentation
46 | pptx;
47 | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
48 | xlsx;
49 | application/vnd.openxmlformats-officedocument.wordprocessingml.document
50 | docx;
51 | application/vnd.wap.wmlc wmlc;
52 | application/x-7z-compressed 7z;
53 | application/x-cocoa cco;
54 | application/x-java-archive-diff jardiff;
55 | application/x-java-jnlp-file jnlp;
56 | application/x-makeself run;
57 | application/x-perl pl pm;
58 | application/x-pilot prc pdb;
59 | application/x-rar-compressed rar;
60 | application/x-redhat-package-manager rpm;
61 | application/x-sea sea;
62 | application/x-shockwave-flash swf;
63 | application/x-stuffit sit;
64 | application/x-tcl tcl tk;
65 | application/x-x509-ca-cert der pem crt;
66 | application/x-xpinstall xpi;
67 | application/xhtml+xml xhtml;
68 | application/xspf+xml xspf;
69 | application/zip zip;
70 |
71 | application/octet-stream bin exe dll;
72 | application/octet-stream deb;
73 | application/octet-stream dmg;
74 | application/octet-stream iso img;
75 | application/octet-stream msi msp msm;
76 |
77 | audio/midi mid midi kar;
78 | audio/mpeg mp3;
79 | audio/ogg ogg;
80 | audio/x-m4a m4a;
81 | audio/x-realaudio ra;
82 |
83 | video/3gpp 3gpp 3gp;
84 | video/mp2t ts;
85 | video/mp4 mp4;
86 | video/mpeg mpeg mpg;
87 | video/quicktime mov;
88 | video/webm webm;
89 | video/x-flv flv;
90 | video/x-m4v m4v;
91 | video/x-mng mng;
92 | video/x-ms-asf asx asf;
93 | video/x-ms-wmv wmv;
94 | video/x-msvideo avi;
95 | }
96 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/nginx.conf:
--------------------------------------------------------------------------------
1 |
2 | #user nobody;
3 | worker_processes 1;
4 |
5 | #error_log logs/error.log;
6 | #error_log logs/error.log notice;
7 | #error_log logs/error.log info;
8 |
9 | #pid logs/nginx.pid;
10 |
11 |
12 | events {
13 | worker_connections 1024;
14 | }
15 |
16 |
17 | http {
18 | include mime.types;
19 | default_type application/octet-stream;
20 |
21 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
22 | # '$status $body_bytes_sent "$http_referer" '
23 | # '"$http_user_agent" "$http_x_forwarded_for"';
24 |
25 | #access_log logs/access.log main;
26 |
27 | sendfile on;
28 | #tcp_nopush on;
29 |
30 | #keepalive_timeout 0;
31 | keepalive_timeout 65;
32 |
33 | #gzip on;
34 |
35 | server {
36 | listen 8080;
37 | server_name localhost;
38 |
39 | #charset koi8-r;
40 |
41 | #access_log logs/host.access.log main;
42 |
43 | location / {
44 | root html;
45 | index index.html index.htm;
46 | }
47 |
48 | #error_page 404 /404.html;
49 |
50 | # redirect server error pages to the static page /50x.html
51 | #
52 | error_page 500 502 503 504 /50x.html;
53 | location = /50x.html {
54 | root html;
55 | }
56 |
57 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80
58 | #
59 | #location ~ \.php$ {
60 | # proxy_pass http://127.0.0.1;
61 | #}
62 |
63 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
64 | #
65 | #location ~ \.php$ {
66 | # root html;
67 | # fastcgi_pass 127.0.0.1:9000;
68 | # fastcgi_index index.php;
69 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 | # include fastcgi_params;
71 | #}
72 |
73 | # deny access to .htaccess files, if Apache's document root
74 | # concurs with nginx's one
75 | #
76 | #location ~ /\.ht {
77 | # deny all;
78 | #}
79 | }
80 |
81 |
82 | # another virtual host using mix of IP-, name-, and port-based configuration
83 | #
84 | #server {
85 | # listen 8000;
86 | # listen somename:8080;
87 | # server_name somename alias another.alias;
88 |
89 | # location / {
90 | # root html;
91 | # index index.html index.htm;
92 | # }
93 | #}
94 |
95 |
96 | # HTTPS server
97 | #
98 | #server {
99 | # listen 443 ssl;
100 | # server_name localhost;
101 |
102 | # ssl_certificate cert.pem;
103 | # ssl_certificate_key cert.key;
104 |
105 | # ssl_session_cache shared:SSL:1m;
106 | # ssl_session_timeout 5m;
107 |
108 | # ssl_ciphers HIGH:!aNULL:!MD5;
109 | # ssl_prefer_server_ciphers on;
110 |
111 | # location / {
112 | # root html;
113 | # index index.html index.htm;
114 | # }
115 | #}
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/nginx.conf.default:
--------------------------------------------------------------------------------
1 |
2 | #user nobody;
3 | worker_processes 1;
4 |
5 | #error_log logs/error.log;
6 | #error_log logs/error.log notice;
7 | #error_log logs/error.log info;
8 |
9 | #pid logs/nginx.pid;
10 |
11 |
12 | events {
13 | worker_connections 1024;
14 | }
15 |
16 |
17 | http {
18 | include mime.types;
19 | default_type application/octet-stream;
20 |
21 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
22 | # '$status $body_bytes_sent "$http_referer" '
23 | # '"$http_user_agent" "$http_x_forwarded_for"';
24 |
25 | #access_log logs/access.log main;
26 |
27 | sendfile on;
28 | #tcp_nopush on;
29 |
30 | #keepalive_timeout 0;
31 | keepalive_timeout 65;
32 |
33 | #gzip on;
34 |
35 | server {
36 | listen 80;
37 | server_name localhost;
38 |
39 | #charset koi8-r;
40 |
41 | #access_log logs/host.access.log main;
42 |
43 | location / {
44 | root html;
45 | index index.html index.htm;
46 | }
47 |
48 | #error_page 404 /404.html;
49 |
50 | # redirect server error pages to the static page /50x.html
51 | #
52 | error_page 500 502 503 504 /50x.html;
53 | location = /50x.html {
54 | root html;
55 | }
56 |
57 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80
58 | #
59 | #location ~ \.php$ {
60 | # proxy_pass http://127.0.0.1;
61 | #}
62 |
63 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
64 | #
65 | #location ~ \.php$ {
66 | # root html;
67 | # fastcgi_pass 127.0.0.1:9000;
68 | # fastcgi_index index.php;
69 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 | # include fastcgi_params;
71 | #}
72 |
73 | # deny access to .htaccess files, if Apache's document root
74 | # concurs with nginx's one
75 | #
76 | #location ~ /\.ht {
77 | # deny all;
78 | #}
79 | }
80 |
81 |
82 | # another virtual host using mix of IP-, name-, and port-based configuration
83 | #
84 | #server {
85 | # listen 8000;
86 | # listen somename:8080;
87 | # server_name somename alias another.alias;
88 |
89 | # location / {
90 | # root html;
91 | # index index.html index.htm;
92 | # }
93 | #}
94 |
95 |
96 | # HTTPS server
97 | #
98 | #server {
99 | # listen 443 ssl;
100 | # server_name localhost;
101 |
102 | # ssl_certificate cert.pem;
103 | # ssl_certificate_key cert.key;
104 |
105 | # ssl_session_cache shared:SSL:1m;
106 | # ssl_session_timeout 5m;
107 |
108 | # ssl_ciphers HIGH:!aNULL:!MD5;
109 | # ssl_prefer_server_ciphers on;
110 |
111 | # location / {
112 | # root html;
113 | # index index.html index.htm;
114 | # }
115 | #}
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/scgi_params:
--------------------------------------------------------------------------------
1 |
2 | scgi_param REQUEST_METHOD $request_method;
3 | scgi_param REQUEST_URI $request_uri;
4 | scgi_param QUERY_STRING $query_string;
5 | scgi_param CONTENT_TYPE $content_type;
6 |
7 | scgi_param DOCUMENT_URI $document_uri;
8 | scgi_param DOCUMENT_ROOT $document_root;
9 | scgi_param SCGI 1;
10 | scgi_param SERVER_PROTOCOL $server_protocol;
11 | scgi_param REQUEST_SCHEME $scheme;
12 | scgi_param HTTPS $https if_not_empty;
13 |
14 | scgi_param REMOTE_ADDR $remote_addr;
15 | scgi_param REMOTE_PORT $remote_port;
16 | scgi_param SERVER_PORT $server_port;
17 | scgi_param SERVER_NAME $server_name;
18 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/scgi_params.default:
--------------------------------------------------------------------------------
1 |
2 | scgi_param REQUEST_METHOD $request_method;
3 | scgi_param REQUEST_URI $request_uri;
4 | scgi_param QUERY_STRING $query_string;
5 | scgi_param CONTENT_TYPE $content_type;
6 |
7 | scgi_param DOCUMENT_URI $document_uri;
8 | scgi_param DOCUMENT_ROOT $document_root;
9 | scgi_param SCGI 1;
10 | scgi_param SERVER_PROTOCOL $server_protocol;
11 | scgi_param REQUEST_SCHEME $scheme;
12 | scgi_param HTTPS $https if_not_empty;
13 |
14 | scgi_param REMOTE_ADDR $remote_addr;
15 | scgi_param REMOTE_PORT $remote_port;
16 | scgi_param SERVER_PORT $server_port;
17 | scgi_param SERVER_NAME $server_name;
18 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/uwsgi_params:
--------------------------------------------------------------------------------
1 |
2 | uwsgi_param QUERY_STRING $query_string;
3 | uwsgi_param REQUEST_METHOD $request_method;
4 | uwsgi_param CONTENT_TYPE $content_type;
5 | uwsgi_param CONTENT_LENGTH $content_length;
6 |
7 | uwsgi_param REQUEST_URI $request_uri;
8 | uwsgi_param PATH_INFO $document_uri;
9 | uwsgi_param DOCUMENT_ROOT $document_root;
10 | uwsgi_param SERVER_PROTOCOL $server_protocol;
11 | uwsgi_param REQUEST_SCHEME $scheme;
12 | uwsgi_param HTTPS $https if_not_empty;
13 |
14 | uwsgi_param REMOTE_ADDR $remote_addr;
15 | uwsgi_param REMOTE_PORT $remote_port;
16 | uwsgi_param SERVER_PORT $server_port;
17 | uwsgi_param SERVER_NAME $server_name;
18 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/uwsgi_params.default:
--------------------------------------------------------------------------------
1 |
2 | uwsgi_param QUERY_STRING $query_string;
3 | uwsgi_param REQUEST_METHOD $request_method;
4 | uwsgi_param CONTENT_TYPE $content_type;
5 | uwsgi_param CONTENT_LENGTH $content_length;
6 |
7 | uwsgi_param REQUEST_URI $request_uri;
8 | uwsgi_param PATH_INFO $document_uri;
9 | uwsgi_param DOCUMENT_ROOT $document_root;
10 | uwsgi_param SERVER_PROTOCOL $server_protocol;
11 | uwsgi_param REQUEST_SCHEME $scheme;
12 | uwsgi_param HTTPS $https if_not_empty;
13 |
14 | uwsgi_param REMOTE_ADDR $remote_addr;
15 | uwsgi_param REMOTE_PORT $remote_port;
16 | uwsgi_param SERVER_PORT $server_port;
17 | uwsgi_param SERVER_NAME $server_name;
18 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/conf/win-utf:
--------------------------------------------------------------------------------
1 |
2 | # This map is not a full windows-1251 <> utf8 map: it does not
3 | # contain Serbian and Macedonian letters. If you need a full map,
4 | # use contrib/unicode2nginx/win-utf map instead.
5 |
6 | charset_map windows-1251 utf-8 {
7 |
8 | 82 E2809A ; # single low-9 quotation mark
9 |
10 | 84 E2809E ; # double low-9 quotation mark
11 | 85 E280A6 ; # ellipsis
12 | 86 E280A0 ; # dagger
13 | 87 E280A1 ; # double dagger
14 | 88 E282AC ; # euro
15 | 89 E280B0 ; # per mille
16 |
17 | 91 E28098 ; # left single quotation mark
18 | 92 E28099 ; # right single quotation mark
19 | 93 E2809C ; # left double quotation mark
20 | 94 E2809D ; # right double quotation mark
21 | 95 E280A2 ; # bullet
22 | 96 E28093 ; # en dash
23 | 97 E28094 ; # em dash
24 |
25 | 99 E284A2 ; # trade mark sign
26 |
27 | A0 C2A0 ; #
28 | A1 D18E ; # capital Byelorussian short U
29 | A2 D19E ; # small Byelorussian short u
30 |
31 | A4 C2A4 ; # currency sign
32 | A5 D290 ; # capital Ukrainian soft G
33 | A6 C2A6 ; # borken bar
34 | A7 C2A7 ; # section sign
35 | A8 D081 ; # capital YO
36 | A9 C2A9 ; # (C)
37 | AA D084 ; # capital Ukrainian YE
38 | AB C2AB ; # left-pointing double angle quotation mark
39 | AC C2AC ; # not sign
40 | AD C2AD ; # soft hypen
41 | AE C2AE ; # (R)
42 | AF D087 ; # capital Ukrainian YI
43 |
44 | B0 C2B0 ; # °
45 | B1 C2B1 ; # plus-minus sign
46 | B2 D086 ; # capital Ukrainian I
47 | B3 D196 ; # small Ukrainian i
48 | B4 D291 ; # small Ukrainian soft g
49 | B5 C2B5 ; # micro sign
50 | B6 C2B6 ; # pilcrow sign
51 | B7 C2B7 ; # ·
52 | B8 D191 ; # small yo
53 | B9 E28496 ; # numero sign
54 | BA D194 ; # small Ukrainian ye
55 | BB C2BB ; # right-pointing double angle quotation mark
56 |
57 | BF D197 ; # small Ukrainian yi
58 |
59 | C0 D090 ; # capital A
60 | C1 D091 ; # capital B
61 | C2 D092 ; # capital V
62 | C3 D093 ; # capital G
63 | C4 D094 ; # capital D
64 | C5 D095 ; # capital YE
65 | C6 D096 ; # capital ZH
66 | C7 D097 ; # capital Z
67 | C8 D098 ; # capital I
68 | C9 D099 ; # capital J
69 | CA D09A ; # capital K
70 | CB D09B ; # capital L
71 | CC D09C ; # capital M
72 | CD D09D ; # capital N
73 | CE D09E ; # capital O
74 | CF D09F ; # capital P
75 |
76 | D0 D0A0 ; # capital R
77 | D1 D0A1 ; # capital S
78 | D2 D0A2 ; # capital T
79 | D3 D0A3 ; # capital U
80 | D4 D0A4 ; # capital F
81 | D5 D0A5 ; # capital KH
82 | D6 D0A6 ; # capital TS
83 | D7 D0A7 ; # capital CH
84 | D8 D0A8 ; # capital SH
85 | D9 D0A9 ; # capital SHCH
86 | DA D0AA ; # capital hard sign
87 | DB D0AB ; # capital Y
88 | DC D0AC ; # capital soft sign
89 | DD D0AD ; # capital E
90 | DE D0AE ; # capital YU
91 | DF D0AF ; # capital YA
92 |
93 | E0 D0B0 ; # small a
94 | E1 D0B1 ; # small b
95 | E2 D0B2 ; # small v
96 | E3 D0B3 ; # small g
97 | E4 D0B4 ; # small d
98 | E5 D0B5 ; # small ye
99 | E6 D0B6 ; # small zh
100 | E7 D0B7 ; # small z
101 | E8 D0B8 ; # small i
102 | E9 D0B9 ; # small j
103 | EA D0BA ; # small k
104 | EB D0BB ; # small l
105 | EC D0BC ; # small m
106 | ED D0BD ; # small n
107 | EE D0BE ; # small o
108 | EF D0BF ; # small p
109 |
110 | F0 D180 ; # small r
111 | F1 D181 ; # small s
112 | F2 D182 ; # small t
113 | F3 D183 ; # small u
114 | F4 D184 ; # small f
115 | F5 D185 ; # small kh
116 | F6 D186 ; # small ts
117 | F7 D187 ; # small ch
118 | F8 D188 ; # small sh
119 | F9 D189 ; # small shch
120 | FA D18A ; # small hard sign
121 | FB D18B ; # small y
122 | FC D18C ; # small soft sign
123 | FD D18D ; # small e
124 | FE D18E ; # small yu
125 | FF D18F ; # small ya
126 | }
127 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/html/50x.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Error
5 |
12 |
13 |
14 | An error occurred.
15 | Sorry, the page you are looking for is currently unavailable.
16 | Please try again later.
17 | If you are the system administrator of this resource then you should check
18 | the error log for details.
19 | Faithfully yours, nginx.
20 |
21 |
22 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Welcome to nginx!
5 |
12 |
13 |
14 | Welcome to nginx!
15 | If you see this page, the nginx web server is successfully installed and
16 | working. Further configuration is required.
17 |
18 | For online documentation and support please refer to
19 | nginx.org.
20 | Commercial support is available at
21 | nginx.com.
22 |
23 | Thank you for using nginx.
24 |
25 |
26 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/assets/nginx/sbin/nginx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/assets/nginx/sbin/nginx
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/java/com/zhangtom/nginxdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhangtom.nginxdemo;
2 |
3 | import android.content.res.AssetManager;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.jrummyapps.android.shell.CommandResult;
11 | import com.jrummyapps.android.shell.Shell;
12 |
13 | import java.io.File;
14 | import java.io.FileOutputStream;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStream;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | private String mNginxDir;
22 | private static final String EXE_FILE_RELATIVE_PATH = "/sbin/nginx";
23 | private static final String CONF_FILE_RELATIVE_PATH = "/conf/nginx.conf";
24 | private static final String TAG = "NGX_DEBUG";
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | mNginxDir = getAppDataDir() + "/nginx";
32 | Button installButton = findViewById(R.id.installButton);
33 | installButton.setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View view) {
36 | copyFileOrDirFromAsset("nginx");
37 | CommandResult result = Shell.SH.run("chmod -R 755 " + mNginxDir);
38 | Log.w(TAG, result.exitCode + "\n" + result.stdout + "\n" + result.stderr);
39 | }
40 | });
41 |
42 | Button startButton = findViewById(R.id.startButton);
43 | startButton.setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View view) {
46 | CommandResult result = Shell.SH.run(mNginxDir + EXE_FILE_RELATIVE_PATH + " -p " + mNginxDir + " -c " + mNginxDir + CONF_FILE_RELATIVE_PATH);
47 | Log.w(TAG, result.exitCode + "\n" + result.stdout + "\n" + result.stderr);
48 | }
49 | });
50 |
51 | Button stopButton = findViewById(R.id.stopButton);
52 | stopButton.setOnClickListener(new View.OnClickListener() {
53 | @Override
54 | public void onClick(View view) {
55 | CommandResult result = Shell.SH.run(mNginxDir + EXE_FILE_RELATIVE_PATH + " -p " + mNginxDir + " -s quit");
56 | Log.w(TAG, result.exitCode + "\n" + result.stdout + "\n" + result.stderr);
57 | }
58 | });
59 | }
60 |
61 | private String getAppDataDir() {
62 | return getApplicationInfo().dataDir;
63 | }
64 |
65 | private void copyFileOrDirFromAsset(String path) {
66 | AssetManager assetManager = this.getAssets();
67 | String assets[];
68 | try {
69 | assets = assetManager.list(path);
70 | if (assets.length == 0) {
71 | copyFile(path);
72 | } else {
73 | String fullPath = getAppDataDir() + "/" + path;
74 | File dir = new File(fullPath);
75 | if (!dir.exists())
76 | dir.mkdir();
77 | for (String asset : assets) {
78 | copyFileOrDirFromAsset(path + "/" + asset);
79 | }
80 | }
81 | } catch (IOException e) {
82 | e.printStackTrace();
83 | }
84 | }
85 |
86 | private void copyFile(String filename) {
87 | AssetManager assetManager = this.getAssets();
88 |
89 | InputStream in;
90 | OutputStream out;
91 | try {
92 | in = assetManager.open(filename);
93 | String newFileName = getAppDataDir() + "/" + filename;
94 | out = new FileOutputStream(newFileName);
95 |
96 | byte[] buffer = new byte[1024];
97 | int read;
98 | while ((read = in.read(buffer)) != -1) {
99 | out.write(buffer, 0, read);
100 | }
101 | in.close();
102 | out.flush();
103 | out.close();
104 | } catch (Exception e) {
105 | e.printStackTrace();
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
23 |
24 |
39 |
40 |
54 |
55 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NginxDemo
3 | Install Nginx
4 | Start Nginx
5 | Stop Nginx
6 |
7 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NginxDemo/app/src/test/java/com/zhangtom/nginxdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zhangtom.nginxdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/NginxDemo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.3'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/NginxDemo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/NginxDemo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatowilson/Cross-Compile-Nginx-with-RTMP-Module-for-Android/0f2cfa0209f9f889200bddcc27ec4c139c0df42a/NginxDemo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/NginxDemo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 28 14:45:54 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/NginxDemo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/NginxDemo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/NginxDemo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Cross Compile Nginx with RTMP Module for Android
2 | See full Chinese explanation blog here: https://zhangtom.com/2017/07/11/交叉编译带RTMP模块的Nginx到Android/
3 |
4 | Succeed on macOS Sierra 10.12.5, macOS High Sierra 10.13.6, Ubuntu 14.04.5, with **Android NDK r15c**
5 |
6 | Feel free to open issue if you have any question.
7 |
8 | # Prerequisites
9 |
10 | * Download latest stable version source code **tarball** of [Nginx](http://nginx.org/en/download.html) (`make_nginx.sh` will extract it automatically)
11 | * Download latest stable version source code of [nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module)
12 | * Download and extract latest LTS version source code of [openssl](https://www.openssl.org/source/) and openssl-fips(no need for openssl-1.1.0 series)
13 | * Download this repo and place source codes as following:
14 | ```
15 | .
16 | ├── Setenv-android.sh
17 | ├── glob (glob.c and glob.h will be copied to nginx/src/os/unix/ by make_nginx.sh)
18 | │ ├── glob.c
19 | │ └── glob.h
20 | ├── portable_cmds.sh
21 | ├── make_nginx.sh
22 | ├── make_openssl.sh
23 | │
24 | ├── nginx-1.12.0/ (this directory is generated by make_nginx.sh during extracting the counterpart tarball file)
25 | │ └── ...
26 | ├── nginx-1.12.0.tar.gz (Nginx source code tarball file, the version could be different)
27 | ├── nginx-rtmp-module/
28 | │ └── ...
29 | ├── openssl-1.1.0f/ (openssl source code directory, the version could be different)
30 | │ └── ...
31 | ├── openssl-fips-2.0.16/ (openssl-fips source code directory, the version could be different, no need for openssl-1.1.0 series)
32 | │ └── ...
33 | └── sdcard (this directory will be generated if compile successfully)
34 | └── nginx
35 | ```
36 | * Download and install `Android SDK` if never installed before, make sure `adb` path is added to environment PATH and it works well
37 | * Download and install `Android NDK` if never installed before, modify `Setenv-android.sh` if needed (`ANDROID_NDK_ROOT`, `_ANDROID_EABI`, `_ANDROID_API`, etc.)
38 |
39 | # Build
40 |
41 | execute these commands in Terminal:
42 | ```bash
43 | # the leading period is important
44 | . ./make_openssl.sh
45 | . ./make_nginx.sh
46 | ```
47 |
48 | # How to run nginx on Android
49 |
50 | See [NginxDemo](NginxDemo).
51 |
52 | # License
53 |
54 | `Setenv-android.sh`: [OpenSSL license]
55 | `glob.c` and `glob.h`([source](https://github.com/white-gecko/TokyoCabinet)): [BSD-3-Clause License]
56 | `other files`: [WTFPL]
57 |
58 | [OpenSSL license]:http://www.openssl.org/source/license.html
59 | [BSD-3-Clause License]:https://opensource.org/licenses/BSD-3-Clause
60 | [WTFPL]: http://www.wtfpl.net/
--------------------------------------------------------------------------------
/Setenv-android.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Cross-compile environment for Android on ARMv7 and x86
3 | #
4 | # Contents licensed under the terms of the OpenSSL license
5 | # http://www.openssl.org/source/license.html
6 | #
7 | # See http://wiki.openssl.org/index.php/FIPS_Library_and_Android
8 | # and http://wiki.openssl.org/index.php/Android
9 |
10 | #####################################################################
11 | export ANDROID_NDK_ROOT=$HOME/Library/Android/sdk/ndk-bundle
12 | # Set ANDROID_NDK_ROOT to you NDK location. For example,
13 | # /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a
14 | # login script. If ANDROID_NDK_ROOT is not specified, the script will
15 | # try to pick it up with the value of _ANDROID_NDK_ROOT below. If
16 | # ANDROID_NDK_ROOT is set, then the value is ignored.
17 | # _ANDROID_NDK="android-ndk-r8e"
18 | _ANDROID_NDK="android-ndk-r9"
19 | # _ANDROID_NDK="android-ndk-r10"
20 |
21 | # Set _ANDROID_EABI to the EABI you want to use. You can find the
22 | # list in $ANDROID_NDK_ROOT/toolchains. This value is always used.
23 | # _ANDROID_EABI="x86-4.6"
24 | # _ANDROID_EABI="arm-linux-androideabi-4.6"
25 | _ANDROID_EABI="arm-linux-androideabi-4.9"
26 |
27 | # Set _ANDROID_ARCH to the architecture you are building for.
28 | # This value is always used.
29 | # _ANDROID_ARCH=arch-x86
30 | _ANDROID_ARCH=arch-arm
31 |
32 | # Set _ANDROID_API to the API you want to use. You should set it
33 | # to one of: android-14, android-9, android-8, android-14, android-5
34 | # android-4, or android-3. You can't set it to the latest (for
35 | # example, API-17) because the NDK does not supply the platform. At
36 | # Android 5.0, there will likely be another platform added (android-22?).
37 | # This value is always used.
38 | # _ANDROID_API="android-14"
39 | _ANDROID_API="android-21"
40 | # _ANDROID_API="android-19"
41 |
42 | #####################################################################
43 |
44 | # If the user did not specify the NDK location, try and pick it up.
45 | # We expect something like ANDROID_NDK_ROOT=/opt/android-ndk-r8e
46 | # or ANDROID_NDK_ROOT=/usr/local/android-ndk-r8e.
47 |
48 | if [ -z "$ANDROID_NDK_ROOT" ]; then
49 |
50 | _ANDROID_NDK_ROOT=""
51 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then
52 | _ANDROID_NDK_ROOT="/usr/local/$_ANDROID_NDK"
53 | fi
54 |
55 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then
56 | _ANDROID_NDK_ROOT="/opt/$_ANDROID_NDK"
57 | fi
58 |
59 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then
60 | _ANDROID_NDK_ROOT="$HOME/$_ANDROID_NDK"
61 | fi
62 |
63 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then
64 | _ANDROID_NDK_ROOT="$PWD/$_ANDROID_NDK"
65 | fi
66 |
67 | # If a path was set, then export it
68 | if [ ! -z "$_ANDROID_NDK_ROOT" ] && [ -d "$_ANDROID_NDK_ROOT" ]; then
69 | export ANDROID_NDK_ROOT="$_ANDROID_NDK_ROOT"
70 | fi
71 | fi
72 |
73 | # Error checking
74 | # ANDROID_NDK_ROOT should always be set by the user (even when not running this script)
75 | # http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77
76 | if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; then
77 | echo "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script."
78 | # echo "$ANDROID_NDK_ROOT"
79 | # exit 1
80 | fi
81 |
82 | # Error checking
83 | if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then
84 | echo "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script."
85 | # echo "$ANDROID_NDK_ROOT/toolchains"
86 | # exit 1
87 | fi
88 |
89 | # Error checking
90 | if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then
91 | echo "Error: ANDROID_EABI is not a valid path. Please edit this script."
92 | # echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI"
93 | # exit 1
94 | fi
95 |
96 | #####################################################################
97 |
98 | # Based on ANDROID_NDK_ROOT, try and pick up the required toolchain. We expect something like:
99 | # /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin
100 | # Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of
101 | # doing things according to the NDK documentation for Ice Cream Sandwich.
102 | # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
103 |
104 | ANDROID_TOOLCHAIN=""
105 | for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
106 | do
107 | if [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then
108 | ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"
109 | break
110 | fi
111 | done
112 |
113 | # Error checking
114 | if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then
115 | echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."
116 | # echo "$ANDROID_TOOLCHAIN"
117 | # exit 1
118 | fi
119 |
120 | case $_ANDROID_ARCH in
121 | arch-arm)
122 | ANDROID_TOOLS=(arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld)
123 | ;;
124 | arch-x86)
125 | ANDROID_TOOLS=(i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld)
126 | ;;
127 | *)
128 | echo "ERROR ERROR ERROR"
129 | ;;
130 | esac
131 |
132 | for tool in ${ANDROID_TOOLS[@]}
133 | do
134 | # Error checking
135 | if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then
136 | echo "Error: Failed to find $tool. Please edit this script."
137 | # echo "$ANDROID_TOOLCHAIN/$tool"
138 | # exit 1
139 | fi
140 | done
141 |
142 | # Only modify/export PATH if ANDROID_TOOLCHAIN good
143 | if [ ! -z "$ANDROID_TOOLCHAIN" ]; then
144 | export ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN"
145 | export PATH="$ANDROID_TOOLCHAIN":"$PATH"
146 | fi
147 |
148 | #####################################################################
149 |
150 | # For the Android SYSROOT. Can be used on the command line with --sysroot
151 | # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
152 | export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
153 | export CROSS_SYSROOT="$ANDROID_SYSROOT"
154 | export NDK_SYSROOT="$ANDROID_SYSROOT"
155 |
156 | # Error checking
157 | if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; then
158 | echo "Error: ANDROID_SYSROOT is not valid. Please edit this script."
159 | # echo "$ANDROID_SYSROOT"
160 | # exit 1
161 | fi
162 |
163 | #####################################################################
164 |
165 | # If the user did not specify the FIPS_SIG location, try and pick it up
166 | # If the user specified a bad location, then try and pick it up too.
167 | if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then
168 |
169 | # Try and locate it
170 | _FIPS_SIG=""
171 | if [ -d "/usr/local/ssl/$_ANDROID_API" ]; then
172 | _FIPS_SIG=`find "/usr/local/ssl/$_ANDROID_API" -name incore`
173 | fi
174 |
175 | if [ ! -e "$_FIPS_SIG" ]; then
176 | _FIPS_SIG=`find $PWD -name incore | head -1`
177 | fi
178 |
179 | # If a path was set, then export it
180 | if [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; then
181 | export FIPS_SIG="$_FIPS_SIG"
182 | fi
183 | fi
184 |
185 | # Error checking. Its OK to ignore this if you are *not* building for FIPS
186 | if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then
187 | echo "Error: FIPS_SIG does not specify incore module. Please edit this script."
188 | # echo "$FIPS_SIG"
189 | # exit 1
190 | fi
191 |
192 | #####################################################################
193 |
194 | # Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored.
195 | export MACHINE=armv7
196 | export RELEASE=2.6.37
197 | export SYSTEM=android
198 | export ARCH=arm
199 | export CROSS_COMPILE="arm-linux-androideabi-"
200 |
201 | if [ "$_ANDROID_ARCH" = "arch-x86" ]; then
202 | export MACHINE=i686
203 | export RELEASE=2.6.37
204 | export SYSTEM=android
205 | export ARCH=x86
206 | export CROSS_COMPILE="i686-linux-android-"
207 | fi
208 |
209 | # For the Android toolchain
210 | # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
211 | export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
212 | export SYSROOT="$ANDROID_SYSROOT"
213 | export NDK_SYSROOT="$ANDROID_SYSROOT"
214 | export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
215 | export ANDROID_API="$_ANDROID_API"
216 |
217 | # CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system.
218 | # export CROSS_COMPILE="arm-linux-androideabi-"
219 | export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
220 | export HOSTCC=gcc
221 |
222 | VERBOSE=1
223 | if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then
224 | echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
225 | echo "ANDROID_ARCH: $_ANDROID_ARCH"
226 | echo "ANDROID_EABI: $_ANDROID_EABI"
227 | echo "ANDROID_API: $ANDROID_API"
228 | echo "ANDROID_SYSROOT: $ANDROID_SYSROOT"
229 | echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN"
230 | echo "FIPS_SIG: $FIPS_SIG"
231 | echo "CROSS_COMPILE: $CROSS_COMPILE"
232 | echo "ANDROID_DEV: $ANDROID_DEV"
233 | fi
234 |
--------------------------------------------------------------------------------
/glob/glob.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Natanael Arndt, 2011: removed collate.h dependencies
3 | * (my changes are trivial)
4 | *
5 | * Copyright (c) 1989, 1993
6 | * The Regents of the University of California. All rights reserved.
7 | *
8 | * This code is derived from software contributed to Berkeley by
9 | * Guido van Rossum.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 4. Neither the name of the University nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 | * SUCH DAMAGE.
34 | */
35 |
36 | #if defined(LIBC_SCCS) && !defined(lint)
37 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
38 | #endif /* LIBC_SCCS and not lint */
39 | #include
40 | __FBSDID("$FreeBSD$");
41 |
42 | /*
43 | * glob(3) -- a superset of the one defined in POSIX 1003.2.
44 | *
45 | * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
46 | *
47 | * Optional extra services, controlled by flags not defined by POSIX:
48 | *
49 | * GLOB_QUOTE:
50 | * Escaping convention: \ inhibits any special meaning the following
51 | * character might have (except \ at end of string is retained).
52 | * GLOB_MAGCHAR:
53 | * Set in gl_flags if pattern contained a globbing character.
54 | * GLOB_NOMAGIC:
55 | * Same as GLOB_NOCHECK, but it will only append pattern if it did
56 | * not contain any magic characters. [Used in csh style globbing]
57 | * GLOB_ALTDIRFUNC:
58 | * Use alternately specified directory access functions.
59 | * GLOB_TILDE:
60 | * expand ~user/foo to the /home/dir/of/user/foo
61 | * GLOB_BRACE:
62 | * expand {1,2}{a,b} to 1a 1b 2a 2b
63 | * gl_matchc:
64 | * Number of matches in the current invocation of glob.
65 | */
66 |
67 | /*
68 | * Some notes on multibyte character support:
69 | * 1. Patterns with illegal byte sequences match nothing - even if
70 | * GLOB_NOCHECK is specified.
71 | * 2. Illegal byte sequences in filenames are handled by treating them as
72 | * single-byte characters with a value of the first byte of the sequence
73 | * cast to wchar_t.
74 | * 3. State-dependent encodings are not currently supported.
75 | */
76 |
77 | #include
78 | #include
79 |
80 | #include
81 | #include
82 | #include
83 | #include
84 | #include
85 | #include
86 | #include
87 | #include
88 | #include
89 | #include
90 | #include
91 | #include
92 |
93 | #define DOLLAR '$'
94 | #define DOT '.'
95 | #define EOS '\0'
96 | #define LBRACKET '['
97 | #define NOT '!'
98 | #define QUESTION '?'
99 | #define QUOTE '\\'
100 | #define RANGE '-'
101 | #define RBRACKET ']'
102 | #define SEP '/'
103 | #define STAR '*'
104 | #define TILDE '~'
105 | #define UNDERSCORE '_'
106 | #define LBRACE '{'
107 | #define RBRACE '}'
108 | #define SLASH '/'
109 | #define COMMA ','
110 |
111 | #ifndef DEBUG
112 |
113 | #define M_QUOTE 0x8000000000ULL
114 | #define M_PROTECT 0x4000000000ULL
115 | #define M_MASK 0xffffffffffULL
116 | #define M_CHAR 0x00ffffffffULL
117 |
118 | typedef uint_fast64_t Char;
119 |
120 | #else
121 |
122 | #define M_QUOTE 0x80
123 | #define M_PROTECT 0x40
124 | #define M_MASK 0xff
125 | #define M_CHAR 0x7f
126 |
127 | typedef char Char;
128 |
129 | #endif
130 |
131 |
132 | #define CHAR(c) ((Char)((c)&M_CHAR))
133 | #define META(c) ((Char)((c)|M_QUOTE))
134 | #define M_ALL META('*')
135 | #define M_END META(']')
136 | #define M_NOT META('!')
137 | #define M_ONE META('?')
138 | #define M_RNG META('-')
139 | #define M_SET META('[')
140 | #define ismeta(c) (((c)&M_QUOTE) != 0)
141 |
142 |
143 | static int compare(const void *, const void *);
144 | static int g_Ctoc(const Char *, char *, size_t);
145 | static int g_lstat(Char *, struct stat *, glob_t *);
146 | static DIR *g_opendir(Char *, glob_t *);
147 | static const Char *g_strchr(const Char *, wchar_t);
148 | #ifdef notdef
149 | static Char *g_strcat(Char *, const Char *);
150 | #endif
151 | static int g_stat(Char *, struct stat *, glob_t *);
152 | static int glob0(const Char *, glob_t *, size_t *);
153 | static int glob1(Char *, glob_t *, size_t *);
154 | static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
155 | static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *);
156 | static int globextend(const Char *, glob_t *, size_t *);
157 | static const Char *
158 | globtilde(const Char *, Char *, size_t, glob_t *);
159 | static int globexp1(const Char *, glob_t *, size_t *);
160 | static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *);
161 | static int match(Char *, Char *, Char *);
162 | #ifdef DEBUG
163 | static void qprintf(const char *, Char *);
164 | #endif
165 |
166 | int
167 | glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
168 | {
169 | const char *patnext;
170 | size_t limit;
171 | Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
172 | mbstate_t mbs;
173 | wchar_t wc;
174 | size_t clen;
175 |
176 | patnext = pattern;
177 | if (!(flags & GLOB_APPEND)) {
178 | pglob->gl_pathc = 0;
179 | pglob->gl_pathv = NULL;
180 | if (!(flags & GLOB_DOOFFS))
181 | pglob->gl_offs = 0;
182 | }
183 | if (flags & GLOB_LIMIT) {
184 | limit = pglob->gl_matchc;
185 | if (limit == 0)
186 | limit = ARG_MAX;
187 | } else
188 | limit = 0;
189 | pglob->gl_flags = flags & ~GLOB_MAGCHAR;
190 | pglob->gl_errfunc = errfunc;
191 | pglob->gl_matchc = 0;
192 |
193 | bufnext = patbuf;
194 | bufend = bufnext + MAXPATHLEN - 1;
195 | if (flags & GLOB_NOESCAPE) {
196 | memset(&mbs, 0, sizeof(mbs));
197 | while (bufend - bufnext >= MB_CUR_MAX) {
198 | clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
199 | if (clen == (size_t)-1 || clen == (size_t)-2)
200 | return (GLOB_NOMATCH);
201 | else if (clen == 0)
202 | break;
203 | *bufnext++ = wc;
204 | patnext += clen;
205 | }
206 | } else {
207 | /* Protect the quoted characters. */
208 | memset(&mbs, 0, sizeof(mbs));
209 | while (bufend - bufnext >= MB_CUR_MAX) {
210 | if (*patnext == QUOTE) {
211 | if (*++patnext == EOS) {
212 | *bufnext++ = QUOTE | M_PROTECT;
213 | continue;
214 | }
215 | prot = M_PROTECT;
216 | } else
217 | prot = 0;
218 | clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
219 | if (clen == (size_t)-1 || clen == (size_t)-2)
220 | return (GLOB_NOMATCH);
221 | else if (clen == 0)
222 | break;
223 | *bufnext++ = wc | prot;
224 | patnext += clen;
225 | }
226 | }
227 | *bufnext = EOS;
228 |
229 | if (flags & GLOB_BRACE)
230 | return globexp1(patbuf, pglob, &limit);
231 | else
232 | return glob0(patbuf, pglob, &limit);
233 | }
234 |
235 | /*
236 | * Expand recursively a glob {} pattern. When there is no more expansion
237 | * invoke the standard globbing routine to glob the rest of the magic
238 | * characters
239 | */
240 | static int
241 | globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
242 | {
243 | const Char* ptr = pattern;
244 | int rv;
245 |
246 | /* Protect a single {}, for find(1), like csh */
247 | if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
248 | return glob0(pattern, pglob, limit);
249 |
250 | while ((ptr = g_strchr(ptr, LBRACE)) != NULL)
251 | if (!globexp2(ptr, pattern, pglob, &rv, limit))
252 | return rv;
253 |
254 | return glob0(pattern, pglob, limit);
255 | }
256 |
257 |
258 | /*
259 | * Recursive brace globbing helper. Tries to expand a single brace.
260 | * If it succeeds then it invokes globexp1 with the new pattern.
261 | * If it fails then it tries to glob the rest of the pattern and returns.
262 | */
263 | static int
264 | globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *limit)
265 | {
266 | int i;
267 | Char *lm, *ls;
268 | const Char *pe, *pm, *pm1, *pl;
269 | Char patbuf[MAXPATHLEN];
270 |
271 | /* copy part up to the brace */
272 | for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
273 | continue;
274 | *lm = EOS;
275 | ls = lm;
276 |
277 | /* Find the balanced brace */
278 | for (i = 0, pe = ++ptr; *pe; pe++)
279 | if (*pe == LBRACKET) {
280 | /* Ignore everything between [] */
281 | for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
282 | continue;
283 | if (*pe == EOS) {
284 | /*
285 | * We could not find a matching RBRACKET.
286 | * Ignore and just look for RBRACE
287 | */
288 | pe = pm;
289 | }
290 | }
291 | else if (*pe == LBRACE)
292 | i++;
293 | else if (*pe == RBRACE) {
294 | if (i == 0)
295 | break;
296 | i--;
297 | }
298 |
299 | /* Non matching braces; just glob the pattern */
300 | if (i != 0 || *pe == EOS) {
301 | *rv = glob0(patbuf, pglob, limit);
302 | return 0;
303 | }
304 |
305 | for (i = 0, pl = pm = ptr; pm <= pe; pm++)
306 | switch (*pm) {
307 | case LBRACKET:
308 | /* Ignore everything between [] */
309 | for (pm1 = pm++; *pm != RBRACKET && *pm != EOS; pm++)
310 | continue;
311 | if (*pm == EOS) {
312 | /*
313 | * We could not find a matching RBRACKET.
314 | * Ignore and just look for RBRACE
315 | */
316 | pm = pm1;
317 | }
318 | break;
319 |
320 | case LBRACE:
321 | i++;
322 | break;
323 |
324 | case RBRACE:
325 | if (i) {
326 | i--;
327 | break;
328 | }
329 | /* FALLTHROUGH */
330 | case COMMA:
331 | if (i && *pm == COMMA)
332 | break;
333 | else {
334 | /* Append the current string */
335 | for (lm = ls; (pl < pm); *lm++ = *pl++)
336 | continue;
337 | /*
338 | * Append the rest of the pattern after the
339 | * closing brace
340 | */
341 | for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
342 | continue;
343 |
344 | /* Expand the current pattern */
345 | #ifdef DEBUG
346 | qprintf("globexp2:", patbuf);
347 | #endif
348 | *rv = globexp1(patbuf, pglob, limit);
349 |
350 | /* move after the comma, to the next string */
351 | pl = pm + 1;
352 | }
353 | break;
354 |
355 | default:
356 | break;
357 | }
358 | *rv = 0;
359 | return 0;
360 | }
361 |
362 |
363 |
364 | /*
365 | * expand tilde from the passwd file.
366 | */
367 | static const Char *
368 | globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
369 | {
370 | struct passwd *pwd;
371 | char *h;
372 | const Char *p;
373 | Char *b, *eb;
374 |
375 | if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
376 | return pattern;
377 |
378 | /*
379 | * Copy up to the end of the string or /
380 | */
381 | eb = &patbuf[patbuf_len - 1];
382 | for (p = pattern + 1, h = (char *) patbuf;
383 | h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
384 | continue;
385 |
386 | *h = EOS;
387 |
388 | if (((char *) patbuf)[0] == EOS) {
389 | /*
390 | * handle a plain ~ or ~/ by expanding $HOME first (iff
391 | * we're not running setuid or setgid) and then trying
392 | * the password file
393 | */
394 | if ((h = getenv("HOME")) == NULL) {
395 | if (((h = getlogin()) != NULL &&
396 | (pwd = getpwnam(h)) != NULL) ||
397 | (pwd = getpwuid(getuid())) != NULL)
398 | h = pwd->pw_dir;
399 | else
400 | return pattern;
401 | }
402 | }
403 | else {
404 | /*
405 | * Expand a ~user
406 | */
407 | if ((pwd = getpwnam((char*) patbuf)) == NULL)
408 | return pattern;
409 | else
410 | h = pwd->pw_dir;
411 | }
412 |
413 | /* Copy the home directory */
414 | for (b = patbuf; b < eb && *h; *b++ = *h++)
415 | continue;
416 |
417 | /* Append the rest of the pattern */
418 | while (b < eb && (*b++ = *p++) != EOS)
419 | continue;
420 | *b = EOS;
421 |
422 | return patbuf;
423 | }
424 |
425 |
426 | /*
427 | * The main glob() routine: compiles the pattern (optionally processing
428 | * quotes), calls glob1() to do the real pattern matching, and finally
429 | * sorts the list (unless unsorted operation is requested). Returns 0
430 | * if things went well, nonzero if errors occurred.
431 | */
432 | static int
433 | glob0(const Char *pattern, glob_t *pglob, size_t *limit)
434 | {
435 | const Char *qpatnext;
436 | int err;
437 | size_t oldpathc;
438 | Char *bufnext, c, patbuf[MAXPATHLEN];
439 |
440 | qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
441 | oldpathc = pglob->gl_pathc;
442 | bufnext = patbuf;
443 |
444 | /* We don't need to check for buffer overflow any more. */
445 | while ((c = *qpatnext++) != EOS) {
446 | switch (c) {
447 | case LBRACKET:
448 | c = *qpatnext;
449 | if (c == NOT)
450 | ++qpatnext;
451 | if (*qpatnext == EOS ||
452 | g_strchr(qpatnext+1, RBRACKET) == NULL) {
453 | *bufnext++ = LBRACKET;
454 | if (c == NOT)
455 | --qpatnext;
456 | break;
457 | }
458 | *bufnext++ = M_SET;
459 | if (c == NOT)
460 | *bufnext++ = M_NOT;
461 | c = *qpatnext++;
462 | do {
463 | *bufnext++ = CHAR(c);
464 | if (*qpatnext == RANGE &&
465 | (c = qpatnext[1]) != RBRACKET) {
466 | *bufnext++ = M_RNG;
467 | *bufnext++ = CHAR(c);
468 | qpatnext += 2;
469 | }
470 | } while ((c = *qpatnext++) != RBRACKET);
471 | pglob->gl_flags |= GLOB_MAGCHAR;
472 | *bufnext++ = M_END;
473 | break;
474 | case QUESTION:
475 | pglob->gl_flags |= GLOB_MAGCHAR;
476 | *bufnext++ = M_ONE;
477 | break;
478 | case STAR:
479 | pglob->gl_flags |= GLOB_MAGCHAR;
480 | /* collapse adjacent stars to one,
481 | * to avoid exponential behavior
482 | */
483 | if (bufnext == patbuf || bufnext[-1] != M_ALL)
484 | *bufnext++ = M_ALL;
485 | break;
486 | default:
487 | *bufnext++ = CHAR(c);
488 | break;
489 | }
490 | }
491 | *bufnext = EOS;
492 | #ifdef DEBUG
493 | qprintf("glob0:", patbuf);
494 | #endif
495 |
496 | if ((err = glob1(patbuf, pglob, limit)) != 0)
497 | return(err);
498 |
499 | /*
500 | * If there was no match we are going to append the pattern
501 | * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
502 | * and the pattern did not contain any magic characters
503 | * GLOB_NOMAGIC is there just for compatibility with csh.
504 | */
505 | if (pglob->gl_pathc == oldpathc) {
506 | if (((pglob->gl_flags & GLOB_NOCHECK) ||
507 | ((pglob->gl_flags & GLOB_NOMAGIC) &&
508 | !(pglob->gl_flags & GLOB_MAGCHAR))))
509 | return(globextend(pattern, pglob, limit));
510 | else
511 | return(GLOB_NOMATCH);
512 | }
513 | if (!(pglob->gl_flags & GLOB_NOSORT))
514 | qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
515 | pglob->gl_pathc - oldpathc, sizeof(char *), compare);
516 | return(0);
517 | }
518 |
519 | static int
520 | compare(const void *p, const void *q)
521 | {
522 | return(strcmp(*(char **)p, *(char **)q));
523 | }
524 |
525 | static int
526 | glob1(Char *pattern, glob_t *pglob, size_t *limit)
527 | {
528 | Char pathbuf[MAXPATHLEN];
529 |
530 | /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
531 | if (*pattern == EOS)
532 | return(0);
533 | return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
534 | pattern, pglob, limit));
535 | }
536 |
537 | /*
538 | * The functions glob2 and glob3 are mutually recursive; there is one level
539 | * of recursion for each segment in the pattern that contains one or more
540 | * meta characters.
541 | */
542 | static int
543 | glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
544 | glob_t *pglob, size_t *limit)
545 | {
546 | struct stat sb;
547 | Char *p, *q;
548 | int anymeta;
549 |
550 | /*
551 | * Loop over pattern segments until end of pattern or until
552 | * segment with meta character found.
553 | */
554 | for (anymeta = 0;;) {
555 | if (*pattern == EOS) { /* End of pattern? */
556 | *pathend = EOS;
557 | if (g_lstat(pathbuf, &sb, pglob))
558 | return(0);
559 |
560 | if (((pglob->gl_flags & GLOB_MARK) &&
561 | pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
562 | || (S_ISLNK(sb.st_mode) &&
563 | (g_stat(pathbuf, &sb, pglob) == 0) &&
564 | S_ISDIR(sb.st_mode)))) {
565 | if (pathend + 1 > pathend_last)
566 | return (GLOB_ABORTED);
567 | *pathend++ = SEP;
568 | *pathend = EOS;
569 | }
570 | ++pglob->gl_matchc;
571 | return(globextend(pathbuf, pglob, limit));
572 | }
573 |
574 | /* Find end of next segment, copy tentatively to pathend. */
575 | q = pathend;
576 | p = pattern;
577 | while (*p != EOS && *p != SEP) {
578 | if (ismeta(*p))
579 | anymeta = 1;
580 | if (q + 1 > pathend_last)
581 | return (GLOB_ABORTED);
582 | *q++ = *p++;
583 | }
584 |
585 | if (!anymeta) { /* No expansion, do next segment. */
586 | pathend = q;
587 | pattern = p;
588 | while (*pattern == SEP) {
589 | if (pathend + 1 > pathend_last)
590 | return (GLOB_ABORTED);
591 | *pathend++ = *pattern++;
592 | }
593 | } else /* Need expansion, recurse. */
594 | return(glob3(pathbuf, pathend, pathend_last, pattern, p,
595 | pglob, limit));
596 | }
597 | /* NOTREACHED */
598 | }
599 |
600 | static int
601 | glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
602 | Char *pattern, Char *restpattern,
603 | glob_t *pglob, size_t *limit)
604 | {
605 | struct dirent *dp;
606 | DIR *dirp;
607 | int err;
608 | char buf[MAXPATHLEN];
609 |
610 | /*
611 | * The readdirfunc declaration can't be prototyped, because it is
612 | * assigned, below, to two functions which are prototyped in glob.h
613 | * and dirent.h as taking pointers to differently typed opaque
614 | * structures.
615 | */
616 | struct dirent *(*readdirfunc)();
617 |
618 | if (pathend > pathend_last)
619 | return (GLOB_ABORTED);
620 | *pathend = EOS;
621 | errno = 0;
622 |
623 | if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
624 | /* TODO: don't call for ENOENT or ENOTDIR? */
625 | if (pglob->gl_errfunc) {
626 | if (g_Ctoc(pathbuf, buf, sizeof(buf)))
627 | return (GLOB_ABORTED);
628 | if (pglob->gl_errfunc(buf, errno) ||
629 | pglob->gl_flags & GLOB_ERR)
630 | return (GLOB_ABORTED);
631 | }
632 | return(0);
633 | }
634 |
635 | err = 0;
636 |
637 | /* Search directory for matching names. */
638 | if (pglob->gl_flags & GLOB_ALTDIRFUNC)
639 | readdirfunc = pglob->gl_readdir;
640 | else
641 | readdirfunc = readdir;
642 | while ((dp = (*readdirfunc)(dirp))) {
643 | char *sc;
644 | Char *dc;
645 | wchar_t wc;
646 | size_t clen;
647 | mbstate_t mbs;
648 |
649 | /* Initial DOT must be matched literally. */
650 | if (dp->d_name[0] == DOT && *pattern != DOT)
651 | continue;
652 | memset(&mbs, 0, sizeof(mbs));
653 | dc = pathend;
654 | sc = dp->d_name;
655 | while (dc < pathend_last) {
656 | clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
657 | if (clen == (size_t)-1 || clen == (size_t)-2) {
658 | wc = *sc;
659 | clen = 1;
660 | memset(&mbs, 0, sizeof(mbs));
661 | }
662 | if ((*dc++ = wc) == EOS)
663 | break;
664 | sc += clen;
665 | }
666 | if (!match(pathend, pattern, restpattern)) {
667 | *pathend = EOS;
668 | continue;
669 | }
670 | err = glob2(pathbuf, --dc, pathend_last, restpattern,
671 | pglob, limit);
672 | if (err)
673 | break;
674 | }
675 |
676 | if (pglob->gl_flags & GLOB_ALTDIRFUNC)
677 | (*pglob->gl_closedir)(dirp);
678 | else
679 | closedir(dirp);
680 | return(err);
681 | }
682 |
683 |
684 | /*
685 | * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
686 | * add the new item, and update gl_pathc.
687 | *
688 | * This assumes the BSD realloc, which only copies the block when its size
689 | * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
690 | * behavior.
691 | *
692 | * Return 0 if new item added, error code if memory couldn't be allocated.
693 | *
694 | * Invariant of the glob_t structure:
695 | * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
696 | * gl_pathv points to (gl_offs + gl_pathc + 1) items.
697 | */
698 | static int
699 | globextend(const Char *path, glob_t *pglob, size_t *limit)
700 | {
701 | char **pathv;
702 | size_t i, newsize, len;
703 | char *copy;
704 | const Char *p;
705 |
706 | if (*limit && pglob->gl_pathc > *limit) {
707 | errno = 0;
708 | return (GLOB_NOSPACE);
709 | }
710 |
711 | newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
712 | pathv = pglob->gl_pathv ?
713 | realloc((char *)pglob->gl_pathv, newsize) :
714 | malloc(newsize);
715 | if (pathv == NULL) {
716 | if (pglob->gl_pathv) {
717 | free(pglob->gl_pathv);
718 | pglob->gl_pathv = NULL;
719 | }
720 | return(GLOB_NOSPACE);
721 | }
722 |
723 | if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
724 | /* first time around -- clear initial gl_offs items */
725 | pathv += pglob->gl_offs;
726 | for (i = pglob->gl_offs + 1; --i > 0; )
727 | *--pathv = NULL;
728 | }
729 | pglob->gl_pathv = pathv;
730 |
731 | for (p = path; *p++;)
732 | continue;
733 | len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
734 | if ((copy = malloc(len)) != NULL) {
735 | if (g_Ctoc(path, copy, len)) {
736 | free(copy);
737 | return (GLOB_NOSPACE);
738 | }
739 | pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
740 | }
741 | pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
742 | return(copy == NULL ? GLOB_NOSPACE : 0);
743 | }
744 |
745 | /*
746 | * pattern matching function for filenames. Each occurrence of the *
747 | * pattern causes a recursion level.
748 | */
749 | static int
750 | match(Char *name, Char *pat, Char *patend)
751 | {
752 | int ok, negate_range;
753 | Char c, k;
754 |
755 | while (pat < patend) {
756 | c = *pat++;
757 | switch (c & M_MASK) {
758 | case M_ALL:
759 | if (pat == patend)
760 | return(1);
761 | do
762 | if (match(name, pat, patend))
763 | return(1);
764 | while (*name++ != EOS);
765 | return(0);
766 | case M_ONE:
767 | if (*name++ == EOS)
768 | return(0);
769 | break;
770 | case M_SET:
771 | ok = 0;
772 | if ((k = *name++) == EOS)
773 | return(0);
774 | if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
775 | ++pat;
776 | while (((c = *pat++) & M_MASK) != M_END)
777 | if ((*pat & M_MASK) == M_RNG) {
778 | if (CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1])) ok = 1;
779 | pat += 2;
780 | } else if (c == k)
781 | ok = 1;
782 | if (ok == negate_range)
783 | return(0);
784 | break;
785 | default:
786 | if (*name++ != c)
787 | return(0);
788 | break;
789 | }
790 | }
791 | return(*name == EOS);
792 | }
793 |
794 | /* Free allocated data belonging to a glob_t structure. */
795 | void
796 | globfree(glob_t *pglob)
797 | {
798 | size_t i;
799 | char **pp;
800 |
801 | if (pglob->gl_pathv != NULL) {
802 | pp = pglob->gl_pathv + pglob->gl_offs;
803 | for (i = pglob->gl_pathc; i--; ++pp)
804 | if (*pp)
805 | free(*pp);
806 | free(pglob->gl_pathv);
807 | pglob->gl_pathv = NULL;
808 | }
809 | }
810 |
811 | static DIR *
812 | g_opendir(Char *str, glob_t *pglob)
813 | {
814 | char buf[MAXPATHLEN];
815 |
816 | if (!*str)
817 | strcpy(buf, ".");
818 | else {
819 | if (g_Ctoc(str, buf, sizeof(buf)))
820 | return (NULL);
821 | }
822 |
823 | if (pglob->gl_flags & GLOB_ALTDIRFUNC)
824 | return((*pglob->gl_opendir)(buf));
825 |
826 | return(opendir(buf));
827 | }
828 |
829 | static int
830 | g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
831 | {
832 | char buf[MAXPATHLEN];
833 |
834 | if (g_Ctoc(fn, buf, sizeof(buf))) {
835 | errno = ENAMETOOLONG;
836 | return (-1);
837 | }
838 | if (pglob->gl_flags & GLOB_ALTDIRFUNC)
839 | return((*pglob->gl_lstat)(buf, sb));
840 | return(lstat(buf, sb));
841 | }
842 |
843 | static int
844 | g_stat(Char *fn, struct stat *sb, glob_t *pglob)
845 | {
846 | char buf[MAXPATHLEN];
847 |
848 | if (g_Ctoc(fn, buf, sizeof(buf))) {
849 | errno = ENAMETOOLONG;
850 | return (-1);
851 | }
852 | if (pglob->gl_flags & GLOB_ALTDIRFUNC)
853 | return((*pglob->gl_stat)(buf, sb));
854 | return(stat(buf, sb));
855 | }
856 |
857 | static const Char *
858 | g_strchr(const Char *str, wchar_t ch)
859 | {
860 |
861 | do {
862 | if (*str == ch)
863 | return (str);
864 | } while (*str++);
865 | return (NULL);
866 | }
867 |
868 | static int
869 | g_Ctoc(const Char *str, char *buf, size_t len)
870 | {
871 | mbstate_t mbs;
872 | size_t clen;
873 |
874 | memset(&mbs, 0, sizeof(mbs));
875 | while (len >= MB_CUR_MAX) {
876 | clen = wcrtomb(buf, *str, &mbs);
877 | if (clen == (size_t)-1)
878 | return (1);
879 | if (*str == L'\0')
880 | return (0);
881 | str++;
882 | buf += clen;
883 | len -= clen;
884 | }
885 | return (1);
886 | }
887 |
888 | #ifdef DEBUG
889 | static void
890 | qprintf(const char *str, Char *s)
891 | {
892 | Char *p;
893 |
894 | (void)printf("%s:\n", str);
895 | for (p = s; *p; p++)
896 | (void)printf("%c", CHAR(*p));
897 | (void)printf("\n");
898 | for (p = s; *p; p++)
899 | (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
900 | (void)printf("\n");
901 | for (p = s; *p; p++)
902 | (void)printf("%c", ismeta(*p) ? '_' : ' ');
903 | (void)printf("\n");
904 | }
905 | #endif
906 |
--------------------------------------------------------------------------------
/glob/glob.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 1989, 1993
3 | * The Regents of the University of California. All rights reserved.
4 | *
5 | * This code is derived from software contributed to Berkeley by
6 | * Guido van Rossum.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | * 3. Neither the name of the University nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 | * SUCH DAMAGE.
31 | *
32 | * @(#)glob.h 8.1 (Berkeley) 6/2/93
33 | * $FreeBSD$
34 | */
35 |
36 | #ifndef _GLOB_H_
37 | #define _GLOB_H_
38 |
39 | #include
40 |
41 | struct stat;
42 | typedef struct {
43 | size_t gl_pathc; /* Count of total paths so far. */
44 | size_t gl_matchc; /* Count of paths matching pattern. */
45 | size_t gl_offs; /* Reserved at beginning of gl_pathv. */
46 | int gl_flags; /* Copy of flags parameter to glob. */
47 | char **gl_pathv; /* List of paths matching pattern. */
48 | /* Copy of errfunc parameter to glob. */
49 | int (*gl_errfunc)(const char *, int);
50 |
51 | /*
52 | * Alternate filesystem access methods for glob; replacement
53 | * versions of closedir(3), readdir(3), opendir(3), stat(2)
54 | * and lstat(2).
55 | */
56 | void (*gl_closedir)(void *);
57 | struct dirent *(*gl_readdir)(void *);
58 | void *(*gl_opendir)(const char *);
59 | int (*gl_lstat)(const char *, struct stat *);
60 | int (*gl_stat)(const char *, struct stat *);
61 | } glob_t;
62 |
63 | #if __POSIX_VISIBLE >= 199209
64 | /* Believed to have been introduced in 1003.2-1992 */
65 | #define GLOB_APPEND 0x0001 /* Append to output from previous call. */
66 | #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
67 | #define GLOB_ERR 0x0004 /* Return on error. */
68 | #define GLOB_MARK 0x0008 /* Append / to matching directories. */
69 | #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
70 | #define GLOB_NOSORT 0x0020 /* Don't sort. */
71 | #define GLOB_NOESCAPE 0x2000 /* Disable backslash escaping. */
72 |
73 | /* Error values returned by glob(3) */
74 | #define GLOB_NOSPACE (-1) /* Malloc call failed. */
75 | #define GLOB_ABORTED (-2) /* Unignored error. */
76 | #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */
77 | #define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */
78 | #endif /* __POSIX_VISIBLE >= 199209 */
79 |
80 | #if __BSD_VISIBLE
81 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
82 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
83 | #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
84 | #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
85 | #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
86 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
87 | #define GLOB_LIMIT 0x1000 /* limit number of returned paths */
88 |
89 | /* source compatibility, these are the old names */
90 | #define GLOB_MAXPATH GLOB_LIMIT
91 | #define GLOB_ABEND GLOB_ABORTED
92 | #endif /* __BSD_VISIBLE */
93 |
94 | __BEGIN_DECLS
95 | int glob(const char *, int, int (*)(const char *, int), glob_t *);
96 | void globfree(glob_t *);
97 | __END_DECLS
98 |
99 | #endif /* !_GLOB_H_ */
100 |
--------------------------------------------------------------------------------
/make_nginx.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "building nginx..."
4 | echo "see logs in make_nginx.log"
5 |
6 | exec > make_nginx.log
7 | exec 2>&1
8 | . ./portable_cmds.sh
9 |
10 | START_DIR=$PWD
11 | RTMP_MODULE_DIR=$START_DIR/nginx-rtmp-module
12 | CROSS_COMPILE_GCC="$ANDROID_TOOLCHAIN/$CROSS_COMPILE"gcc
13 | export DESTDIR=$START_DIR
14 | export CC_AUX_FLAGS="--sysroot=$ANDROID_SYSROOT"
15 |
16 | NGINX_SRC_PKG=$(p_find ".*nginx-[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz")
17 | if [ -z $NGINX_SRC_PKG ]; then
18 | echo "Can't find nginx source package! Aborting." >/dev/tty
19 | exit 1
20 | fi
21 | NGINX_SRC_DIR=${NGINX_SRC_PKG%.tar.gz}
22 | if [ -d $NGINX_SRC_DIR ]; then
23 | rm -r $NGINX_SRC_DIR
24 | fi
25 | tar xzf $NGINX_SRC_PKG
26 | command -v adb >/dev/null 2>&1 || { echo >&2 "This script needs adb, but it's not found. Install it and add its path to `PATH`. Aborting." >/dev/tty; exit 1; }
27 | cd $NGINX_SRC_DIR
28 |
29 | # modify the auto files and run autotests on Android using adb
30 | # these commands work well on macOS
31 | _ADB_PUSH_AUTOTEST='adb push $NGX_AUTOTEST /data/local/tmp 2>\&1 >/dev/null'
32 | _ADB_RM_AUTOTEST='adb shell rm /data/local/tmp/$(basename $NGX_AUTOTEST)'
33 | _ADB_RUN_AUTOTEST='adb shell /data/local/tmp/$(basename $NGX_AUTOTEST)'
34 | sed -i -e 's@\( *\)case "$ngx_feature_run" in@\1'"$_ADB_PUSH_AUTOTEST"'\
35 | &@' auto/feature
36 | sed -i -e 's@\( *\)esac@&\
37 | \1'"$_ADB_RM_AUTOTEST"'@' auto/feature
38 | sed -i -e 's@/bin/sh -c $NGX_AUTOTEST@'"$_ADB_RUN_AUTOTEST"'@' auto/feature
39 | sed -i -e 's@`$NGX_AUTOTEST`@`'"$_ADB_RUN_AUTOTEST"'`@' auto/feature
40 | # specify --sysroot for autotest in auto/include by adding $CC_AUX_FLAGS (already export above)
41 | sed -i -e 's@ngx_test="$CC -o $NGX_AUTOTEST $NGX_AUTOTEST.c"@ngx_test="$CC $CC_AUX_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c"@' auto/include
42 | sed -i -e 's@\( *\)ngx_size=`$NGX_AUTOTEST`@\1'"$_ADB_PUSH_AUTOTEST"'\
43 | \1ngx_size=`'"$_ADB_RUN_AUTOTEST"'`\
44 | \1'"$_ADB_RM_AUTOTEST"'@' auto/types/sizeof
45 | # remove unnecessary sub-directory ".openssl/" for already cross-compiled openssl library
46 | sed -i -e 's@\.openssl/@@' auto/lib/openssl/conf
47 | # add glob.h and glob.c to sources
48 | _SRC_OS_UNIX_DIR=src/os/unix
49 | cp ../glob/glob.h $_SRC_OS_UNIX_DIR
50 | cp ../glob/glob.c $_SRC_OS_UNIX_DIR
51 | sed -i -e 's@UNIX_DEPS=.*@&\
52 | '$_SRC_OS_UNIX_DIR/glob.h' \\@' auto/sources
53 | sed -i -e 's@UNIX_SRCS=.*@&\
54 | '$_SRC_OS_UNIX_DIR/glob.c' \\@' auto/sources
55 | # replace crypt() with DES_crypt() in openssl
56 | sed -i -e 's@#include @&\
57 | #include @' $_SRC_OS_UNIX_DIR/ngx_user.c
58 | sed -i -e 's@value = crypt((char \*) key, (char \*) salt);@value = DES_crypt((char \*) key, (char \*) salt);@' $_SRC_OS_UNIX_DIR/ngx_user.c
59 |
60 | ./configure \
61 | --crossbuild=android-arm \
62 | --prefix=/sdcard/nginx \
63 | --with-http_ssl_module \
64 | --with-openssl=$OPENSSL_DIR \
65 | --without-http_gzip_module \
66 | --without-pcre \
67 | --without-http_rewrite_module \
68 | --without-http_proxy_module \
69 | --without-http_userid_module \
70 | --without-http_upstream_zone_module \
71 | --without-stream_upstream_zone_module \
72 | --add-module=$RTMP_MODULE_DIR \
73 | --with-cc=$CROSS_COMPILE_GCC \
74 | --with-cc-opt="--sysroot=$ANDROID_SYSROOT -Wno-sign-compare -pie -fPIE" \
75 | --with-ld-opt="--sysroot=$ANDROID_SYSROOT -pie -fPIE"
76 |
77 | make -j8
78 | make install -j8
79 |
80 | cd ..
81 | exec >/dev/tty
82 | exec 2>&1
83 |
--------------------------------------------------------------------------------
/make_openssl.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "building openssl..."
4 | echo "see logs in make_openssl.log"
5 |
6 | exec > make_openssl.log
7 | exec 2>&1
8 |
9 | . ./portable_cmds.sh
10 | . ./Setenv-android.sh
11 | export OPENSSL_DIR=$PWD/ssl/$ANDROID_API
12 |
13 | if [ -e $OPENSSL_DIR ]; then
14 | rm -r $OPENSSL_DIR
15 | fi
16 |
17 | # enter openssl source code directory
18 | OPENSSL_SRC_DIR=$(p_find ".*openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]")
19 | if [[ -z $OPENSSL_SRC_DIR ]]; then
20 | echo "Can't find openssl source directory!"
21 | exit 1
22 | fi
23 | cd $OPENSSL_SRC_DIR
24 |
25 | # generate Makefile
26 | KERNEL_BITS=32 ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine \
27 | --openssldir=$OPENSSL_DIR --prefix=$OPENSSL_DIR
28 | make depend
29 | make all
30 | make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib
31 |
32 | cd ..
33 | exec >/dev/tty
34 | exec 2>&1
35 |
--------------------------------------------------------------------------------
/portable_cmds.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | p_find() {
4 | case $(uname) in
5 | Darwin*)
6 | find -E . -regex $1
7 | ;;
8 | Linux*)
9 | find . -regex $1
10 | ;;
11 | esac
12 | }
--------------------------------------------------------------------------------