├── .gitignore
├── LICENSE.txt
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── release
│ ├── app-release.apk
│ └── output.json
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ └── com
│ │ └── example
│ │ └── httpinfo
│ │ ├── MainActivity.java
│ │ ├── MyApplication.java
│ │ ├── OkHttpUrlLoader.java
│ │ ├── ResultActivity.java
│ │ ├── ResultBean.java
│ │ └── adapter
│ │ ├── BaseRecyclerAdapter.java
│ │ ├── BaseRecyclerHolder.java
│ │ └── ResultAdapter.java
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ ├── ic_launcher_background.xml
│ └── main_activity_start_btn.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── activity_result.xml
│ └── item_activity_result_rv.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── values-zh-rCN
│ └── strings.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── httpmodel
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── fairy
│ └── easy
│ └── httpmodel
│ ├── HttpModelHelper.java
│ ├── load
│ └── HttpException.java
│ ├── model
│ ├── Headers.java
│ ├── HttpModel.java
│ ├── HttpNormalUrlLoader.java
│ ├── Key.java
│ ├── LazyHeaderFactory.java
│ ├── LazyHeaders.java
│ ├── ModelLoader.java
│ ├── PostParam.java
│ └── RequestMethod.java
│ ├── resource
│ ├── Factory.java
│ ├── HttpFactory.java
│ ├── HttpListener.java
│ ├── HttpType.java
│ ├── Input.java
│ ├── base
│ │ ├── BaseBean.java
│ │ └── BaseData.java
│ ├── dns
│ │ ├── DnsBean.java
│ │ └── DnsHelper.java
│ ├── host
│ │ ├── HostBean.java
│ │ └── HostHelper.java
│ ├── http
│ │ ├── HttpBean.java
│ │ └── HttpHelper.java
│ ├── index
│ │ ├── IndexBean.java
│ │ └── IndexHelper.java
│ ├── mtu
│ │ ├── MtuBean.java
│ │ └── MtuHelper.java
│ ├── net
│ │ ├── NetBean.java
│ │ └── NetHelper.java
│ ├── ping
│ │ ├── PingBean.java
│ │ └── PingHelper.java
│ ├── port
│ │ ├── PortBean.java
│ │ └── PortHelper.java
│ └── traceroute
│ │ ├── TraceRouteBean.java
│ │ └── TraceRouteHelper.java
│ ├── server
│ ├── A6Record.java
│ ├── AAAARecord.java
│ ├── AFSDBRecord.java
│ ├── APLRecord.java
│ ├── ARecord.java
│ ├── Address.java
│ ├── CAARecord.java
│ ├── CDNSKEYRecord.java
│ ├── CDSRecord.java
│ ├── CERTRecord.java
│ ├── CNAMERecord.java
│ ├── Cache.java
│ ├── Client.java
│ ├── ClientSubnetOption.java
│ ├── Compression.java
│ ├── Credibility.java
│ ├── DClass.java
│ ├── DHCIDRecord.java
│ ├── DLVRecord.java
│ ├── DNAMERecord.java
│ ├── DNSInput.java
│ ├── DNSKEYRecord.java
│ ├── DNSOutput.java
│ ├── DNSSEC.java
│ ├── DSRecord.java
│ ├── EDNSOption.java
│ ├── EmptyRecord.java
│ ├── ExtendedFlags.java
│ ├── ExtendedResolver.java
│ ├── Flags.java
│ ├── FormattedTime.java
│ ├── GPOSRecord.java
│ ├── Generator.java
│ ├── GenericEDNSOption.java
│ ├── HINFORecord.java
│ ├── Header.java
│ ├── IPSECKEYRecord.java
│ ├── ISDNRecord.java
│ ├── InvalidDClassException.java
│ ├── InvalidTTLException.java
│ ├── InvalidTypeException.java
│ ├── KEYBase.java
│ ├── KEYRecord.java
│ ├── KXRecord.java
│ ├── LOCRecord.java
│ ├── Lookup.java
│ ├── MBRecord.java
│ ├── MDRecord.java
│ ├── MFRecord.java
│ ├── MGRecord.java
│ ├── MINFORecord.java
│ ├── MRRecord.java
│ ├── MXRecord.java
│ ├── Master.java
│ ├── Message.java
│ ├── Mnemonic.java
│ ├── NAPTRRecord.java
│ ├── NSAPRecord.java
│ ├── NSAP_PTRRecord.java
│ ├── NSEC3PARAMRecord.java
│ ├── NSEC3Record.java
│ ├── NSECRecord.java
│ ├── NSIDOption.java
│ ├── NSRecord.java
│ ├── NULLRecord.java
│ ├── NXTRecord.java
│ ├── Name.java
│ ├── NameTooLongException.java
│ ├── OPENPGPKEYRecord.java
│ ├── OPTRecord.java
│ ├── Opcode.java
│ ├── Options.java
│ ├── PTRRecord.java
│ ├── PXRecord.java
│ ├── PacketLogger.java
│ ├── RPRecord.java
│ ├── RRSIGRecord.java
│ ├── RRset.java
│ ├── RTRecord.java
│ ├── Rcode.java
│ ├── Record.java
│ ├── RelativeNameException.java
│ ├── ResolveThread.java
│ ├── Resolver.java
│ ├── ResolverConfig.java
│ ├── ResolverListener.java
│ ├── ReverseMap.java
│ ├── SIG0.java
│ ├── SIGBase.java
│ ├── SIGRecord.java
│ ├── SMIMEARecord.java
│ ├── SOARecord.java
│ ├── SPFRecord.java
│ ├── SRVRecord.java
│ ├── SSHFPRecord.java
│ ├── Section.java
│ ├── Serial.java
│ ├── SetResponse.java
│ ├── SimpleResolver.java
│ ├── SingleCompressedNameBase.java
│ ├── SingleNameBase.java
│ ├── TCPClient.java
│ ├── TKEYRecord.java
│ ├── TLSARecord.java
│ ├── TSIG.java
│ ├── TSIGRecord.java
│ ├── TTL.java
│ ├── TXTBase.java
│ ├── TXTRecord.java
│ ├── TextParseException.java
│ ├── Tokenizer.java
│ ├── Type.java
│ ├── TypeBitmap.java
│ ├── U16NameBase.java
│ ├── UDPClient.java
│ ├── UNKRecord.java
│ ├── URIRecord.java
│ ├── Update.java
│ ├── WKSRecord.java
│ ├── WireParseException.java
│ ├── X25Record.java
│ ├── Zone.java
│ ├── ZoneTransferException.java
│ ├── ZoneTransferIn.java
│ └── utils
│ │ ├── base16.java
│ │ ├── base32.java
│ │ ├── base64.java
│ │ └── hexdump.java
│ └── util
│ ├── Base.java
│ ├── Date.java
│ ├── Dns.java
│ ├── Host.java
│ ├── Http.java
│ ├── HttpLog.java
│ ├── IPTools.java
│ ├── LogTime.java
│ ├── MtuScan.java
│ ├── Net.java
│ ├── NetWork.java
│ ├── Output.java
│ ├── Ping.java
│ ├── PortScan.java
│ ├── PortScanTCP.java
│ ├── PortScanUDP.java
│ ├── Preconditions.java
│ ├── Task.java
│ └── TraceRoute.java
├── param.gif
├── settings.gradle
└── src
├── download.png
├── http-cn.json
└── http-en.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## HttpInfo
4 |
5 | **`Android`Network Diagnostic Tool**
6 |
7 | [ ](https://bintray.com/guxiaonian/maven/http/_latestVersion)
8 | [](https://github.com/guxiaonian/HttpInfo/issues)
9 | [](https://github.com/guxiaonian/HttpInfo/network)
10 | [](https://github.com/guxiaonian/HttpInfo/stargazers)
11 | [](http://www.apache.org/licenses/LICENSE-2.0)
12 |
13 | ## APP Download
14 |
15 | 
16 |
17 |
18 |
19 |
20 | # Dependencies
21 |
22 | ```gradle
23 | implementation 'fairy.easy:httpmodel:{latest-version}'
24 |
25 | ```
26 |
27 | ## [WIKI](https://github.com/guxiaonian/HttpInfo/wiki)
28 |
29 | ## ChangeLog
30 |
31 | version|update content|updated
32 | -----|-----|-----
33 | **1.0.5** |1、sdk for dependency optimization| 2020-01-07
34 | **1.0.4** |1、Modify TraceRoute timeout time to 1s| 2019-12-29
35 | **1.0.3** |1、Modify the MtuScan settings, change to multi-threaded concurrent, and set the timeout period to 1s| 2019-09-29
36 | **1.0.2** |1、Add Net related options| 2019-08-13
37 |
38 |
39 | # Precautions
40 |
41 | * There is a complete JSON data format under the `src` file for easy viewing.
42 |
43 | # Display
44 |
45 | 
46 |
47 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /src/androidTest
3 | /src/test
4 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.example.httpinfo"
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-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | sourceCompatibility = '1.8'
21 | targetCompatibility = '1.8'
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation 'com.android.support:appcompat-v7:28.0.0'
28 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
32 | implementation project(':httpmodel')
33 | //依赖外部网络库
34 | implementation 'com.squareup.okhttp3:okhttp:4.1.0'
35 | //demo设计
36 | implementation 'com.android.support:design:28.0.0'
37 | implementation 'com.android.support:cardview-v7:28.0.0'
38 | }
39 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/release/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/release/app-release.apk
--------------------------------------------------------------------------------
/app/release/output.json:
--------------------------------------------------------------------------------
1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
21 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/com/example/httpinfo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.httpinfo;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.support.v4.app.ActivityCompat;
7 | import android.support.v4.content.ContextCompat;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.text.TextUtils;
11 | import android.view.View;
12 | import android.widget.CheckBox;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 | public static final String HTTP_ADDRESS = "http";
18 | public static final String HTTP_RB = "rb";
19 |
20 | private EditText etInput;
21 | private CheckBox radioButton;
22 |
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 | setTitle(getString(R.string.main_net));
29 | //获取手机强度使用
30 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
31 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
32 | }
33 |
34 | etInput = findViewById(R.id.main_activity_et_input);
35 | radioButton = findViewById(R.id.main_activity_start_rb);
36 |
37 | findViewById(R.id.main_activity_start_btn).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | if (TextUtils.isEmpty(etInput.getText().toString())) {
41 | Toast.makeText(getApplicationContext(), "Input Address is wrong", Toast.LENGTH_SHORT).show();
42 | return;
43 | }
44 | Intent intent = new Intent(getApplicationContext(), ResultActivity.class);
45 | intent.putExtra(HTTP_ADDRESS, etInput.getText().toString());
46 | intent.putExtra(HTTP_RB, radioButton.isChecked());
47 | startActivity(intent);
48 | }
49 | });
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/httpinfo/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.httpinfo;
2 |
3 | import android.app.Application;
4 |
5 |
6 | public class MyApplication extends Application {
7 |
8 | @Override
9 | public void onCreate() {
10 | super.onCreate();
11 |
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/httpinfo/ResultBean.java:
--------------------------------------------------------------------------------
1 | package com.example.httpinfo;
2 |
3 | import java.io.Serializable;
4 |
5 |
6 | public class ResultBean implements Serializable {
7 | private String title;
8 | private Object param;
9 |
10 | public ResultBean(String title, Object param) {
11 | this.title = title;
12 | this.param = param;
13 | }
14 |
15 | public String getTitle() {
16 | return title;
17 | }
18 |
19 | public void setTitle(String title) {
20 | this.title = title;
21 | }
22 |
23 | public Object getParam() {
24 | return param;
25 | }
26 |
27 | public void setParam(Object param) {
28 | this.param = param;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/httpinfo/adapter/BaseRecyclerHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.httpinfo.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.SparseArray;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 |
11 | public class BaseRecyclerHolder extends RecyclerView.ViewHolder {
12 |
13 | private SparseArray viewSparseArray;
14 | private Context context;
15 |
16 | private BaseRecyclerHolder(View itemView, Context context) {
17 | super(itemView);
18 | this.context = context;
19 | viewSparseArray = new SparseArray<>(8);
20 | }
21 |
22 | /**
23 | * 拿到实体类
24 | *
25 | * @param itemView
26 | * @param context
27 | * @return
28 | */
29 | public static BaseRecyclerHolder getRecyclerHolder(View itemView, Context context) {
30 | return new BaseRecyclerHolder(itemView, context);
31 | }
32 |
33 | /**
34 | * 拿到所有的控件
35 | *
36 | * @return
37 | */
38 | public SparseArray getViews() {
39 | return this.viewSparseArray;
40 | }
41 |
42 | /**
43 | * 拿到view的id来获取控件
44 | *
45 | * @param viewId
46 | * @param
47 | * @return
48 | */
49 | public T getView(int viewId) {
50 | View view = viewSparseArray.get(viewId);
51 | if (view == null) {
52 | view = itemView.findViewById(viewId);
53 | viewSparseArray.put(viewId, view);
54 | }
55 | return (T) view;
56 | }
57 |
58 | public BaseRecyclerHolder setText(int viewId, String text) {
59 | TextView textView = getView(viewId);
60 | if (text == null) {
61 | textView.setVisibility(View.GONE);
62 | } else {
63 | textView.setVisibility(View.VISIBLE);
64 | textView.setText(text);
65 | }
66 | return this;
67 | }
68 |
69 | public BaseRecyclerHolder setVisibility(int viewId, int visible) {
70 | View view = getView(viewId);
71 | view.setVisibility(visible);
72 | return this;
73 | }
74 |
75 |
76 | public BaseRecyclerHolder setImageViewByResource(int viewId, int drawableId) {
77 | ImageView imageView = getView(viewId);
78 | imageView.setImageResource(drawableId);
79 | return this;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/httpinfo/adapter/ResultAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.httpinfo.adapter;
2 |
3 | import android.content.Context;
4 |
5 | import com.example.httpinfo.R;
6 | import com.example.httpinfo.ResultBean;
7 |
8 |
9 | /**
10 | * Created by gunaonian on 2018/3/30.
11 | */
12 |
13 | public class ResultAdapter extends BaseRecyclerAdapter {
14 |
15 | public ResultAdapter(Context context, int itemLayoutId) {
16 | super(context, itemLayoutId);
17 | }
18 |
19 | @Override
20 | public void convert(BaseRecyclerHolder baseRecyclerHolder, ResultBean item, int position) {
21 | baseRecyclerHolder.setText(R.id.item_activity_result_rv_tv, item.getTitle());
22 | baseRecyclerHolder.setText(R.id.item_activity_result_rv_tv_param, formatString(item.getParam().toString()));
23 | }
24 |
25 | public static String formatString(String text) {
26 |
27 | StringBuilder json = new StringBuilder();
28 | String indentString = "";
29 |
30 | for (int i = 0; i < text.length(); i++) {
31 | char letter = text.charAt(i);
32 | switch (letter) {
33 | case '{':
34 | case '[':
35 | json.append(indentString + letter + "\n");
36 | indentString = indentString + "\t";
37 | json.append(indentString);
38 | break;
39 | case '}':
40 | case ']':
41 | indentString = indentString.replaceFirst("\t", "");
42 | json.append("\n" + indentString + letter);
43 | break;
44 | case ',':
45 | json.append(letter + "\n" + indentString);
46 | break;
47 |
48 | default:
49 | json.append(letter);
50 | break;
51 | }
52 | }
53 |
54 | return json.toString();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/main_activity_start_btn.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
6 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
28 |
29 |
39 |
40 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_activity_result_rv.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
24 |
25 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 网络诊断
3 | 网络诊断
4 | 请输入网址
5 | 开始诊断
6 | 诊断结果
7 | 客官稍等哦~~马上测试完成
8 | 诊断成功
9 | 评测成功,总耗时
10 | 中文
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Net Diagnosis
3 | Net Diagnosis
4 | Please enter the URL
5 | Start Diagnosis
6 | Diagnostic Result
7 | Wait a minute~~The test will be completed immediately
8 | Diagnostic Success
9 | Successful evaluation, total time-consuming
10 | Chinese
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.3.1'
11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
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 | tasks.withType(Javadoc) {
24 | options.addStringOption('Xdoclint:none', '-quiet')
25 | options.addStringOption('encoding', 'UTF-8')
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/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 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 24 16:26:24 CST 2019
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.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/httpmodel/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /src/androidTest
3 | /src/test
4 |
--------------------------------------------------------------------------------
/httpmodel/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 |
--------------------------------------------------------------------------------
/httpmodel/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/load/HttpException.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.load;
2 |
3 | import java.io.IOException;
4 |
5 |
6 | @SuppressWarnings({"WeakerAccess", "unused"})
7 | public final class HttpException extends IOException {
8 | private static final long serialVersionUID = 1L;
9 |
10 | public static final int UNKNOWN = -1;
11 | private final int statusCode;
12 |
13 | public HttpException(int statusCode) {
14 | this("Http request failed with status code: " + statusCode, statusCode);
15 | }
16 |
17 | public HttpException(String message) {
18 | this(message, UNKNOWN);
19 | }
20 |
21 | public HttpException(String message, int statusCode) {
22 | this(message, statusCode, null);
23 | }
24 |
25 | public HttpException(String message, int statusCode, Throwable cause) {
26 | super(message, cause);
27 | this.statusCode = statusCode;
28 | }
29 |
30 | public int getStatusCode() {
31 | return statusCode;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/model/Headers.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.model;
2 |
3 | import java.util.Collections;
4 | import java.util.Map;
5 |
6 |
7 | public interface Headers {
8 |
9 | Headers NONE = new Headers() {
10 | @Override
11 | public Map getHeaders() {
12 | return Collections.emptyMap();
13 | }
14 | };
15 |
16 |
17 | Headers DEFAULT = new LazyHeaders.Builder().build();
18 |
19 |
20 | Map getHeaders();
21 | }
22 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/model/Key.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.model;
2 |
3 |
4 | import java.nio.charset.Charset;
5 | import java.security.MessageDigest;
6 |
7 | public interface Key {
8 | String STRING_CHARSET_NAME = "UTF-8";
9 | String GBK_CHARSET_NAME = "GBK";
10 | Charset CHARSET = Charset.forName(STRING_CHARSET_NAME);
11 |
12 | void updateDiskCacheKey( MessageDigest messageDigest);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/model/LazyHeaderFactory.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.model;
2 |
3 |
4 |
5 | public interface LazyHeaderFactory {
6 |
7 | String buildHeader();
8 | }
9 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/model/ModelLoader.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.model;
2 |
3 |
4 | public interface ModelLoader {
5 |
6 | interface DataCallback {
7 |
8 | void onDataReady( T data);
9 |
10 |
11 | void onLoadFailed( Exception e);
12 | }
13 |
14 | void loadData( DataCallback super T> callback);
15 |
16 | void cleanup();
17 |
18 | void cancel();
19 |
20 | ModelLoader setHttpModel(HttpModel httpModel);
21 |
22 |
23 | ModelLoader setTimeout(int timeout);
24 |
25 | Class getDataClass();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/model/PostParam.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.model;
2 |
3 | import org.json.JSONObject;
4 |
5 | import java.util.Map;
6 |
7 | public class PostParam {
8 |
9 | private final String param;
10 | private JSONObject jsonObject;
11 | private Map map;
12 |
13 | public PostParam(JSONObject jsonObject) {
14 | this.jsonObject = jsonObject;
15 | this.param = jsonObject == null ? null : jsonObject.toString();
16 | }
17 |
18 | public PostParam(Map map) {
19 | this.map = map;
20 | this.param = getMapData(map);
21 | }
22 |
23 | public PostParam(String param) {
24 | this.param = param;
25 | }
26 |
27 | public String getStringParam() {
28 | return param;
29 | }
30 |
31 | public JSONObject getJSONObjectParam() {
32 | return jsonObject;
33 | }
34 |
35 | public Map getMapParam() {
36 | return map;
37 | }
38 |
39 | private String getMapData(Map map) {
40 |
41 | StringBuilder stringBuilder = new StringBuilder();
42 |
43 | try {
44 | for (Map.Entry entry : map.entrySet()) {
45 | stringBuilder.append(entry.getKey())
46 | .append("=")
47 | .append(entry.getKey())
48 | .append("&");
49 | }
50 | stringBuilder.deleteCharAt(stringBuilder.length() - 1);
51 | } catch (Exception e) {
52 | //ignore
53 |
54 | }
55 | return stringBuilder.toString();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/model/RequestMethod.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.model;
2 |
3 | public enum RequestMethod {
4 | GET("GET"),
5 | POST("POST");
6 |
7 |
8 | String name;
9 |
10 | RequestMethod(String name) {
11 | this.name = name;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/Factory.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource;
2 |
3 | public interface Factory {
4 | void getData();
5 | }
6 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/HttpListener.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource;
2 |
3 | import org.json.JSONObject;
4 |
5 | public interface HttpListener {
6 |
7 | void onSuccess(HttpType httpType, JSONObject result);
8 |
9 | void onFail(String data);
10 |
11 | void onFinish(JSONObject result);
12 | }
13 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/HttpType.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource;
2 |
3 | public enum HttpType {
4 | INDEX("Index"),
5 | PING("Ping"),
6 | HTTP("Http"),
7 | HOST("Host"),
8 | PORT_SCAN("PortScan"),
9 | MTU_SCAN("MtuScan"),
10 | TRACE_ROUTE("TraceRoute"),
11 | NSLOOKUP("NsLookup"),
12 | NET("Net");
13 |
14 | private String name;
15 |
16 | HttpType(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getName() {
21 | return name;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/Input.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import fairy.easy.httpmodel.HttpModelHelper;
10 | import fairy.easy.httpmodel.util.HttpLog;
11 | import fairy.easy.httpmodel.util.LogTime;
12 |
13 | public class Input {
14 | public static boolean isMainThread() {
15 | return Looper.getMainLooper() == Looper.myLooper();
16 | }
17 |
18 | public static Handler mainHandler = new Handler(Looper.getMainLooper());
19 |
20 | private static final String ALL_TIME = "totalTime";
21 |
22 | private static JSONObject totalJson;
23 | private static int index;
24 |
25 | public static void onSuccess(final HttpType httpType, final JSONObject result) {
26 | if (isMainThread()) {
27 | HttpModelHelper.getInstance().getHttpListener().onSuccess(httpType, result);
28 | addJson(httpType, result);
29 | } else {
30 | mainHandler.post(new Runnable() {
31 | @Override
32 | public void run() {
33 | HttpModelHelper.getInstance().getHttpListener().onSuccess(httpType, result);
34 | addJson(httpType, result);
35 | }
36 | });
37 | }
38 | }
39 |
40 | private static void addJson(HttpType httpType, JSONObject result) {
41 | if (totalJson == null) {
42 | totalJson = new JSONObject();
43 | }
44 | index++;
45 | try {
46 | totalJson.put(httpType.getName(), result);
47 | } catch (JSONException e) {
48 | e.printStackTrace();
49 | }
50 | if (index == HttpModelHelper.getInstance().getHttpTypeSize()) {
51 | try {
52 | totalJson.put(ALL_TIME, LogTime.getElapsedMillis(HttpModelHelper.getInstance().getInitTime())+ "ms");
53 | } catch (JSONException e) {
54 | e.printStackTrace();
55 | }
56 | HttpModelHelper.getInstance().getHttpListener().onFinish(totalJson);
57 | totalJson = null;
58 | index = 0;
59 | }
60 | }
61 |
62 | public static void onFail(final String error) {
63 | HttpLog.e(error);
64 | if (isMainThread()) {
65 | HttpModelHelper.getInstance().getHttpListener().onFail(error);
66 | } else {
67 | mainHandler.post(new Runnable() {
68 | @Override
69 | public void run() {
70 | HttpModelHelper.getInstance().getHttpListener().onFail(error);
71 | }
72 | });
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/base/BaseBean.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.base;
2 |
3 |
4 | import org.json.JSONObject;
5 |
6 | import java.io.Serializable;
7 |
8 | import fairy.easy.httpmodel.HttpModelHelper;
9 | import fairy.easy.httpmodel.util.HttpLog;
10 |
11 |
12 | public class BaseBean implements Serializable {
13 |
14 | protected JSONObject jsonObject = new JSONObject();
15 |
16 |
17 | protected JSONObject toJSONObject() {
18 | HttpLog.i(jsonObject.toString());
19 | return jsonObject;
20 | }
21 |
22 | protected BaseBean() {
23 |
24 | }
25 |
26 | public boolean isChina() {
27 | return HttpModelHelper.getInstance().isChina();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/base/BaseData.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.base;
2 |
3 | public class BaseData {
4 |
5 | public static final String BASE = ":";
6 |
7 | /**
8 | * 使用腾讯云相关接口 当腾讯云接口不行当时候 也可以使用网易接口
9 | */
10 | public static final String BASE_URL = "https://huatuo.qq.com/";
11 | public static final String OUTPUT_IP_URL = "Report/GetUserIp";
12 | public static final String OUTPUT_IP_COUNTRY_URL = "Report/GetIsp";
13 | public static final String RESPONSE_SERVER_URL = "Report/GetUrlResponseServer";
14 |
15 |
16 | /**
17 | * 使用网易接口
18 | */
19 | public static final String OUTPUT_DNS_URL = "https://nstool.netease.com/";
20 |
21 |
22 | public static final int HTTP_ERROR = -1;
23 | public static final int HTTP_SUCCESS = 200;
24 | }
25 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/host/HostBean.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.host;
2 |
3 | import org.json.JSONArray;
4 | import org.json.JSONException;
5 | import org.json.JSONObject;
6 |
7 | import java.util.List;
8 |
9 | import fairy.easy.httpmodel.resource.base.BaseBean;
10 |
11 | public class HostBean extends BaseBean {
12 |
13 | private int status;
14 |
15 | private List param;
16 |
17 | public int getStatus() {
18 | return status;
19 | }
20 |
21 | private int totalTime;
22 |
23 | public int getTotalTime() {
24 | return totalTime;
25 | }
26 |
27 | public void setTotalTime(int totalTime) {
28 | this.totalTime = totalTime;
29 | }
30 |
31 | public void setStatus(int status) {
32 | this.status = status;
33 | }
34 |
35 | public List getParam() {
36 | return param;
37 | }
38 |
39 | public void setParam(List param) {
40 | this.param = param;
41 | }
42 |
43 | public HostBean() {
44 | }
45 |
46 | @Override
47 | protected JSONObject toJSONObject() {
48 | try {
49 | jsonObject.put(isChina() ? HostData.STATUS_CN : HostData.STATUS, status);
50 | jsonObject.put(isChina() ? HostData.PARAM_CN : HostData.PARAM, new JSONArray(param));
51 | jsonObject.put(isChina() ? HostData.TOTALTIME_CN : HostData.TOTALTIME, totalTime + "ms");
52 | } catch (JSONException e) {
53 | e.printStackTrace();
54 | }
55 | return super.toJSONObject();
56 | }
57 |
58 | public static class HostData {
59 | public static final String TOTALTIME = "totalTime";
60 | public static final String TOTALTIME_CN = "总消耗时间";
61 | public static final String STATUS = "status";
62 | public static final String STATUS_CN = "执行结果";
63 | public static final String PARAM = "param";
64 | public static final String PARAM_CN = "详细信息";
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/host/HostHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.host;
2 |
3 | import fairy.easy.httpmodel.resource.HttpType;
4 | import fairy.easy.httpmodel.resource.Input;
5 | import fairy.easy.httpmodel.util.Host;
6 | import fairy.easy.httpmodel.util.HttpLog;
7 | import fairy.easy.httpmodel.util.LogTime;
8 |
9 | public class HostHelper {
10 |
11 | public static void getHostParam() throws Exception {
12 | long startTime = LogTime.getLogTime();
13 | HostBean hostBean = Host.getLocalHost();
14 | hostBean.setTotalTime(LogTime.getElapsedMillis(startTime));
15 | HttpLog.i("Host is end");
16 | Input.onSuccess(HttpType.HOST, hostBean.toJSONObject());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/http/HttpHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.http;
2 |
3 | import android.net.TrafficStats;
4 |
5 | import fairy.easy.httpmodel.HttpModelHelper;
6 | import fairy.easy.httpmodel.resource.HttpType;
7 | import fairy.easy.httpmodel.resource.Input;
8 | import fairy.easy.httpmodel.util.Http;
9 | import fairy.easy.httpmodel.util.HttpLog;
10 | import fairy.easy.httpmodel.util.LogTime;
11 |
12 | public class HttpHelper {
13 |
14 | public static void getHttpParam() throws Exception {
15 | long startTime = LogTime.getLogTime();
16 | Http http = new Http(HttpModelHelper.getInstance().getAddress());
17 | long totalTraffic=TrafficStats.getTotalRxBytes();
18 | HttpBean httpBean = http.getHttpInfo();
19 | int time=LogTime.getElapsedMillis(startTime);
20 | //网速单位为Bytes B/ms 转变成bpms==kbps
21 | httpBean.setSpeed((int) (TrafficStats.getTotalRxBytes()-totalTraffic)/time*8);
22 | httpBean.setTime(time);
23 | http.getResponseServer();
24 | httpBean.setTotalTime(LogTime.getElapsedMillis(startTime));
25 | HttpLog.i("Http is end");
26 | Input.onSuccess(HttpType.HTTP, httpBean.toJSONObject());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/index/IndexBean.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.index;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import fairy.easy.httpmodel.resource.base.BaseBean;
7 |
8 | public class IndexBean extends BaseBean {
9 |
10 | private String address="*";
11 | private String time="*";
12 |
13 | public IndexBean() {
14 | }
15 |
16 | public String getAddress() {
17 | return address;
18 | }
19 |
20 | public String getTime() {
21 | return time;
22 | }
23 |
24 | public void setAddress(String address) {
25 | this.address = address;
26 | }
27 |
28 | public void setTime(String time) {
29 | this.time = time;
30 | }
31 |
32 | @Override
33 | protected JSONObject toJSONObject() {
34 | try {
35 | jsonObject.put(isChina() ? IndexData.ADDRESS_CN : IndexData.ADDRESS, address);
36 | jsonObject.put(isChina() ? IndexData.TIME_CN : IndexData.TIME, time);
37 | } catch (JSONException e) {
38 | //ignore
39 | }
40 | return super.toJSONObject();
41 | }
42 |
43 | public static class IndexData {
44 | public static final String ADDRESS = "address";
45 | public static final String ADDRESS_CN = "测速地址";
46 | public static final String TIME = "time";
47 | public static final String TIME_CN = "请求时间";
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/index/IndexHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.index;
2 |
3 |
4 | import fairy.easy.httpmodel.HttpModelHelper;
5 | import fairy.easy.httpmodel.resource.HttpType;
6 | import fairy.easy.httpmodel.resource.Input;
7 | import fairy.easy.httpmodel.util.Date;
8 | import fairy.easy.httpmodel.util.HttpLog;
9 |
10 | public class IndexHelper {
11 |
12 | public static void getIndexParam() throws Exception {
13 | IndexBean indexBean = new IndexBean();
14 | indexBean.setAddress(HttpModelHelper.getInstance().getAddress());
15 | indexBean.setTime(Date.stampToDate(System.currentTimeMillis()));
16 | HttpLog.i("Index is end");
17 | Input.onSuccess(HttpType.INDEX, indexBean.toJSONObject());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/mtu/MtuBean.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.mtu;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import fairy.easy.httpmodel.resource.base.BaseBean;
7 |
8 | public class MtuBean extends BaseBean {
9 |
10 | private int status;
11 | private int mtu;
12 | private int totalTime;
13 |
14 | public MtuBean() {
15 | }
16 |
17 | public int getTotalTime() {
18 | return totalTime;
19 | }
20 |
21 | public void setTotalTime(int totalTime) {
22 | this.totalTime = totalTime;
23 | }
24 |
25 | public int getStatus() {
26 | return status;
27 | }
28 |
29 | public void setStatus(int status) {
30 | this.status = status;
31 | }
32 |
33 | public int getMtu() {
34 | return mtu;
35 | }
36 |
37 | public void setMtu(int mtu) {
38 | this.mtu = mtu;
39 | }
40 |
41 | @Override
42 | protected JSONObject toJSONObject() {
43 | try {
44 | jsonObject.put(isChina() ? MtuData.STATUS_CN : MtuData.STATUS, status);
45 | jsonObject.put(isChina() ? MtuData.MTU_CN : MtuData.MTU, mtu + "bytes");
46 | jsonObject.put(isChina() ? MtuData.TOTALTIME_CN : MtuData.TOTALTIME, totalTime + "ms");
47 | } catch (JSONException e) {
48 | //ignore
49 | }
50 | return super.toJSONObject();
51 | }
52 |
53 | public static class MtuData {
54 | public static final String STATUS = "status";
55 | public static final String STATUS_CN = "执行结果";
56 | public static final String MTU = "mtu";
57 | public static final String MTU_CN = "传输单元";
58 | public static final String TOTALTIME_CN = "总消耗时间";
59 | public static final String TOTALTIME = "totalTime";
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/mtu/MtuHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.mtu;
2 |
3 |
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | import fairy.easy.httpmodel.resource.HttpType;
8 | import fairy.easy.httpmodel.resource.Input;
9 | import fairy.easy.httpmodel.resource.base.BaseData;
10 | import fairy.easy.httpmodel.util.Base;
11 | import fairy.easy.httpmodel.util.HttpLog;
12 | import fairy.easy.httpmodel.util.LogTime;
13 | import fairy.easy.httpmodel.util.MtuScan;
14 |
15 | public class MtuHelper {
16 |
17 | public static void getMtuParam() throws Exception {
18 | long startTime = LogTime.getLogTime();
19 | MtuScan mtuScan = new MtuScan(Base.getUrlHost());
20 | List mtuList = mtuScan.startReturnValue();
21 | MtuBean mtuBean = new MtuBean();
22 | if (mtuList.size() == 0) {
23 | mtuBean.setStatus(BaseData.HTTP_ERROR);
24 | } else {
25 | mtuBean.setStatus(BaseData.HTTP_SUCCESS);
26 | Collections.sort(mtuList);
27 | mtuBean.setMtu(mtuList.get(mtuList.size() - 1) + 28);
28 | }
29 | mtuScan.cancelMtuScan();
30 | mtuBean.setTotalTime(LogTime.getElapsedMillis(startTime));
31 | HttpLog.i("MtuScan is end");
32 | Input.onSuccess(HttpType.MTU_SCAN, mtuBean.toJSONObject());
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/net/NetHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.net;
2 |
3 | import android.content.Context;
4 |
5 | import fairy.easy.httpmodel.HttpModelHelper;
6 | import fairy.easy.httpmodel.resource.HttpType;
7 | import fairy.easy.httpmodel.resource.Input;
8 | import fairy.easy.httpmodel.util.Dns;
9 | import fairy.easy.httpmodel.util.HttpLog;
10 | import fairy.easy.httpmodel.util.LogTime;
11 | import fairy.easy.httpmodel.util.Net;
12 |
13 | import static fairy.easy.httpmodel.util.NetWork.isNetworkAvailable;
14 |
15 | public class NetHelper {
16 |
17 | public static void getNetParam() throws Exception {
18 | long startTime = LogTime.getLogTime();
19 | final NetBean netBean = new NetBean();
20 | Context context = HttpModelHelper.getInstance().getContext();
21 | netBean.setNetworkAvailable(isNetworkAvailable(context));
22 | netBean.setNetWorkType(Net.networkType(context));
23 | netBean.setMobileType(Net.networkTypeMobile(context));
24 | netBean.setWifiRssi(Net.getWifiRssi(context));
25 | netBean.setWifiLevel(Net.calculateSignalLevel(netBean.getWifiRssi()));
26 | netBean.setWifiLevelValue(Net.checkSignalRssi(netBean.getWifiLevel()));
27 | netBean.setIp(Net.getClientIp());
28 | netBean.setDns(Dns.readDnsServers(context).length>0?Dns.readDnsServers(context)[0]:"*");
29 | Net.getOutPutDns(netBean);
30 | netBean.setRoaming(Net.checkIsRoaming(context));
31 | Net.getMobileDbm(context, netBean);
32 | netBean.setMobLevelValue(Net.checkSignalRssi(netBean.getMobLevel()));
33 | netBean.setTotalName(LogTime.getElapsedMillis(startTime));
34 | HttpLog.i("Net is end");
35 | Input.onSuccess(HttpType.NET, netBean.toJSONObject());
36 | }
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/ping/PingHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.ping;
2 |
3 | import fairy.easy.httpmodel.HttpModelHelper;
4 | import fairy.easy.httpmodel.resource.HttpType;
5 | import fairy.easy.httpmodel.resource.Input;
6 | import fairy.easy.httpmodel.util.HttpLog;
7 | import fairy.easy.httpmodel.util.Ping;
8 |
9 | public class PingHelper {
10 |
11 | public static void getPingParam() throws Exception {
12 | Ping ping = new Ping(HttpModelHelper.getInstance().getAddress());
13 | PingBean pingBean = ping.getPingInfo();
14 | HttpLog.i("Ping is end");
15 | Input.onSuccess(HttpType.PING, pingBean.toJSONObject());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/port/PortHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.port;
2 |
3 | import org.json.JSONObject;
4 |
5 | import java.net.UnknownHostException;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import fairy.easy.httpmodel.HttpModelHelper;
10 | import fairy.easy.httpmodel.resource.HttpType;
11 | import fairy.easy.httpmodel.resource.Input;
12 | import fairy.easy.httpmodel.resource.base.BaseData;
13 | import fairy.easy.httpmodel.util.Base;
14 | import fairy.easy.httpmodel.util.HttpLog;
15 | import fairy.easy.httpmodel.util.LogTime;
16 | import fairy.easy.httpmodel.util.PortScan;
17 |
18 | public class PortHelper {
19 |
20 | public static void getPortParam() throws Exception {
21 | long startTime = LogTime.getLogTime();
22 | final PortBean portBean = new PortBean();
23 | portBean.setAddress(HttpModelHelper.getInstance().getAddress());
24 | final List list = new ArrayList<>();
25 | try {
26 |
27 | PortScan.onAddress(Base.getUrlHost())
28 | .setPortsPrivileged()
29 | .setMethodTCP()
30 | .doScan(new PortScan.PortListener() {
31 | @Override
32 | public void onResult(PortBean.PortNetBean portNetBean) {
33 | if (portNetBean.isConnected()) {
34 | list.add(portNetBean.toJSONObject());
35 | }
36 | }
37 |
38 |
39 | @Override
40 | public void onFinished(ArrayList openPorts) {
41 | portBean.setStatus(BaseData.HTTP_SUCCESS);
42 | portBean.setPortNetBeans(list);
43 |
44 | }
45 | });
46 | } catch (UnknownHostException e) {
47 | portBean.setStatus(BaseData.HTTP_ERROR);
48 | e.printStackTrace();
49 | }
50 | portBean.setTotalTime(LogTime.getElapsedMillis(startTime));
51 | HttpLog.i("PortScan is end");
52 | Input.onSuccess(HttpType.PORT_SCAN, portBean.toJSONObject());
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/resource/traceroute/TraceRouteHelper.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.resource.traceroute;
2 |
3 |
4 | import android.text.TextUtils;
5 |
6 | import org.json.JSONObject;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import fairy.easy.httpmodel.resource.HttpType;
12 | import fairy.easy.httpmodel.resource.Input;
13 | import fairy.easy.httpmodel.resource.base.BaseData;
14 | import fairy.easy.httpmodel.util.Base;
15 | import fairy.easy.httpmodel.util.HttpLog;
16 | import fairy.easy.httpmodel.util.LogTime;
17 | import fairy.easy.httpmodel.util.Output;
18 | import fairy.easy.httpmodel.util.TraceRoute;
19 |
20 | public class TraceRouteHelper {
21 |
22 | public static void getTraceRouteParam() throws Exception {
23 | long startTime = LogTime.getLogTime();
24 | final TraceRouteBean routeBean = new TraceRouteBean();
25 | final List list = new ArrayList<>();
26 | TraceRoute.getInstance().startTraceRoute(Base.getUrlHost(), new TraceRoute.TraceRouteListener() {
27 | @Override
28 | public void onNetTraceUpdated(TraceRouteBean.TraceRouteDataBean traceRouteBean) {
29 | try {
30 | checkIpCountry(traceRouteBean);
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 | list.add(traceRouteBean.toJSONObject());
35 | }
36 |
37 | @Override
38 | public void onNetTraceFinished(boolean status) {
39 | routeBean.setStatus(status ? BaseData.HTTP_SUCCESS : BaseData.HTTP_ERROR);
40 | routeBean.setList(list);
41 | }
42 | });
43 | routeBean.setTotalTime(LogTime.getElapsedMillis(startTime));
44 | HttpLog.i("TraceRoute is end");
45 | Input.onSuccess(HttpType.TRACE_ROUTE, routeBean.toJSONObject());
46 |
47 | }
48 |
49 | private static void checkIpCountry(final TraceRouteBean.TraceRouteDataBean traceRouteBean) throws Exception {
50 | String ip = traceRouteBean.getIp();
51 | if (TextUtils.isEmpty(ip) || "*".equals(ip)) {
52 | traceRouteBean.setCountry("未知");
53 | } else if (ip.startsWith("192.168")) {
54 | traceRouteBean.setCountry("私网地址");
55 | } else {
56 | if (ip.contains("(") && ip.contains(")")) {
57 | ip = ip.substring(ip.indexOf("(") + 1, ip.indexOf(")"));
58 | }
59 | Output.getOutPutIpCountry(new Output.OutPutListener() {
60 | @Override
61 | public void onSuccess(String s) {
62 | traceRouteBean.setCountry(s);
63 | }
64 |
65 | @Override
66 | public void onFail(Exception e) {
67 | traceRouteBean.setCountry("未知");
68 | }
69 | }, ip);
70 |
71 | }
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/AAAARecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 | import java.net.*;
7 |
8 | /**
9 | * IPv6 Address Record - maps a domain name to an IPv6 address
10 | *
11 | * @author Brian Wellington
12 | * @see RFC 3596: DNS Extensions to Support IP Version 6
13 | */
14 | public class AAAARecord extends Record {
15 |
16 | private static final long serialVersionUID = -4588601512069748050L;
17 |
18 | private byte[] address;
19 |
20 | AAAARecord() {
21 | }
22 |
23 | @Override
24 | Record
25 | getObject() {
26 | return new AAAARecord();
27 | }
28 |
29 | /**
30 | * Creates an AAAA Record from the given data
31 | *
32 | * @param address The address suffix
33 | */
34 | public AAAARecord(Name name, int dclass, long ttl, InetAddress address) {
35 | super(name, Type.AAAA, dclass, ttl);
36 | if (Address.familyOf(address) != Address.IPv6)
37 | throw new IllegalArgumentException("invalid IPv6 address");
38 | this.address = address.getAddress();
39 | }
40 |
41 | @Override
42 | void
43 | rrFromWire(DNSInput in) throws IOException {
44 | address = in.readByteArray(16);
45 | }
46 |
47 | @Override
48 | void
49 | rdataFromString(Tokenizer st, Name origin) throws IOException {
50 | address = st.getAddressBytes(Address.IPv6);
51 | }
52 |
53 | /**
54 | * Converts rdata to a String
55 | */
56 | @Override
57 | String
58 | rrToString() {
59 | InetAddress addr;
60 | try {
61 | addr = InetAddress.getByAddress(null, address);
62 | } catch (UnknownHostException e) {
63 | return null;
64 | }
65 | if (addr.getAddress().length == 4) {
66 | // Deal with Java's broken handling of mapped IPv4 addresses.
67 | StringBuilder sb = new StringBuilder("0:0:0:0:0:ffff:");
68 | int high = ((address[12] & 0xFF) << 8) + (address[13] & 0xFF);
69 | int low = ((address[14] & 0xFF) << 8) + (address[15] & 0xFF);
70 | sb.append(Integer.toHexString(high));
71 | sb.append(':');
72 | sb.append(Integer.toHexString(low));
73 | return sb.toString();
74 | }
75 | return addr.getHostAddress();
76 | }
77 |
78 | /**
79 | * Returns the address
80 | */
81 | public InetAddress
82 | getAddress() {
83 | try {
84 | if (name == null)
85 | return InetAddress.getByAddress(address);
86 | else
87 | return InetAddress.getByAddress(name.toString(),
88 | address);
89 | } catch (UnknownHostException e) {
90 | return null;
91 | }
92 | }
93 |
94 | @Override
95 | void
96 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
97 | out.writeByteArray(address);
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/AFSDBRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * AFS Data Base Record - maps a domain name to the name of an AFS cell
7 | * database server.
8 | *
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 1183: New DNS RR Definitions
12 | */
13 | public class AFSDBRecord extends U16NameBase {
14 |
15 | private static final long serialVersionUID = 3034379930729102437L;
16 |
17 | AFSDBRecord() {}
18 |
19 | @Override
20 | Record
21 | getObject() {
22 | return new AFSDBRecord();
23 | }
24 |
25 | /**
26 | * Creates an AFSDB Record from the given data.
27 | * @param subtype Indicates the type of service provided by the host.
28 | * @param host The host providing the service.
29 | */
30 | public
31 | AFSDBRecord(Name name, int dclass, long ttl, int subtype, Name host) {
32 | super(name, Type.AFSDB, dclass, ttl, subtype, "subtype", host, "host");
33 | }
34 |
35 | /** Gets the subtype indicating the service provided by the host. */
36 | public int
37 | getSubtype() {
38 | return getU16Field();
39 | }
40 |
41 | /** Gets the host providing service for the domain. */
42 | public Name
43 | getHost() {
44 | return getNameField();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/ARecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.net.*;
6 | import java.io.*;
7 |
8 | /**
9 | * Address Record - maps a domain name to an Internet address
10 | *
11 | * @author Brian Wellington
12 | * @see RFC 1035: Domain Names - Implementation and Specification
13 | */
14 | public class ARecord extends Record {
15 |
16 | private static final long serialVersionUID = -2172609200849142323L;
17 |
18 | private int addr;
19 |
20 | ARecord() {}
21 |
22 | @Override
23 | Record
24 | getObject() {
25 | return new ARecord();
26 | }
27 |
28 | private static int
29 | fromArray(byte [] array) {
30 | return (((array[0] & 0xFF) << 24) |
31 | ((array[1] & 0xFF) << 16) |
32 | ((array[2] & 0xFF) << 8) |
33 | (array[3] & 0xFF));
34 | }
35 |
36 | private static byte []
37 | toArray(int addr) {
38 | byte [] bytes = new byte[4];
39 | bytes[0] = (byte) ((addr >>> 24) & 0xFF);
40 | bytes[1] = (byte) ((addr >>> 16) & 0xFF);
41 | bytes[2] = (byte) ((addr >>> 8) & 0xFF);
42 | bytes[3] = (byte) (addr & 0xFF);
43 | return bytes;
44 | }
45 |
46 | /**
47 | * Creates an A Record from the given data
48 | * @param address The address that the name refers to
49 | */
50 | public
51 | ARecord(Name name, int dclass, long ttl, InetAddress address) {
52 | super(name, Type.A, dclass, ttl);
53 | if (Address.familyOf(address) != Address.IPv4)
54 | throw new IllegalArgumentException("invalid IPv4 address");
55 | addr = fromArray(address.getAddress());
56 | }
57 |
58 | @Override
59 | void
60 | rrFromWire(DNSInput in) throws IOException {
61 | addr = fromArray(in.readByteArray(4));
62 | }
63 |
64 | @Override
65 | void
66 | rdataFromString(Tokenizer st, Name origin) throws IOException {
67 | addr = fromArray(st.getAddressBytes(Address.IPv4));
68 | }
69 |
70 | /** Converts rdata to a String */
71 | @Override
72 | String
73 | rrToString() {
74 | return (Address.toDottedQuad(toArray(addr)));
75 | }
76 |
77 | /** Returns the Internet address */
78 | public InetAddress
79 | getAddress() {
80 | try {
81 | if (name == null)
82 | return InetAddress.getByAddress(toArray(addr));
83 | else
84 | return InetAddress.getByAddress(name.toString(),
85 | toArray(addr));
86 | } catch (UnknownHostException e) {
87 | return null;
88 | }
89 | }
90 |
91 | @Override
92 | void
93 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
94 | out.writeU32(((long)addr) & 0xFFFFFFFFL);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/CAARecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Certification Authority Authorization
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 6844: DNS Certification Authority Authorization (CAA) Resource Record
12 | */
13 | public class CAARecord extends Record {
14 |
15 | private static final long serialVersionUID = 8544304287274216443L;
16 |
17 | public static class Flags {
18 | private Flags() {}
19 |
20 | public static final int IssuerCritical = 128;
21 | }
22 |
23 | private int flags;
24 | private byte [] tag;
25 | private byte [] value;
26 |
27 | CAARecord() {}
28 |
29 | @Override
30 | Record
31 | getObject() {
32 | return new CAARecord();
33 | }
34 |
35 | /**
36 | * Creates an CAA Record from the given data.
37 | * @param flags The flags.
38 | * @param tag The tag.
39 | * @param value The value.
40 | */
41 | public
42 | CAARecord(Name name, int dclass, long ttl, int flags, String tag, String value)
43 | {
44 | super(name, Type.CAA, dclass, ttl);
45 | this.flags = checkU8("flags", flags);
46 | try {
47 | this.tag = byteArrayFromString(tag);
48 | this.value = byteArrayFromString(value);
49 | }
50 | catch (TextParseException e) {
51 | throw new IllegalArgumentException(e.getMessage());
52 | }
53 | }
54 |
55 | @Override
56 | void
57 | rrFromWire(DNSInput in) throws IOException {
58 | flags = in.readU8();
59 | tag = in.readCountedString();
60 | value = in.readByteArray();
61 | }
62 |
63 | @Override
64 | void
65 | rdataFromString(Tokenizer st, Name origin) throws IOException {
66 | flags = st.getUInt8();
67 | try {
68 | tag = byteArrayFromString(st.getString());
69 | value = byteArrayFromString(st.getString());
70 | }
71 | catch (TextParseException e) {
72 | throw st.exception(e.getMessage());
73 | }
74 | }
75 |
76 | @Override
77 | String
78 | rrToString() {
79 | StringBuilder sb = new StringBuilder();
80 | sb.append(flags);
81 | sb.append(" ");
82 | sb.append(byteArrayToString(tag, false));
83 | sb.append(" ");
84 | sb.append(byteArrayToString(value, true));
85 | return sb.toString();
86 | }
87 |
88 | /** Returns the flags. */
89 | public int
90 | getFlags() {
91 | return flags;
92 | }
93 |
94 | /** Returns the tag. */
95 | public String
96 | getTag() {
97 | return byteArrayToString(tag, false);
98 | }
99 |
100 | /** Returns the value */
101 | public String
102 | getValue() {
103 | return byteArrayToString(value, false);
104 | }
105 |
106 | @Override
107 | void
108 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
109 | out.writeU8(flags);
110 | out.writeCountedString(tag);
111 | out.writeByteArray(value);
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/CDNSKEYRecord.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: BSD-2-Clause
2 | package fairy.easy.httpmodel.server;
3 |
4 | import java.security.PublicKey;
5 |
6 | /**
7 | * Child DNSKEY record as specified in RFC 8078.
8 | *
9 | * @see DNSSEC
10 | * @see RFC 8078: Managing DS Records from the Parent via CDS/CDNSKEY
11 | */
12 | public class CDNSKEYRecord extends DNSKEYRecord {
13 |
14 | private static final long serialVersionUID = 1307874430666933615L;
15 |
16 | CDNSKEYRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new CDNSKEYRecord();
22 | }
23 |
24 | /**
25 | * Creates a CDNSKEY Record from the given data
26 | * @param flags Flags describing the key's properties
27 | * @param proto The protocol that the key was created for
28 | * @param alg The key's algorithm
29 | * @param key Binary representation of the key
30 | */
31 | public
32 | CDNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
33 | byte [] key)
34 | {
35 | super(name, Type.CDNSKEY, dclass, ttl, flags, proto, alg, key);
36 | }
37 |
38 | /**
39 | * Creates a CDNSKEY Record from the given data
40 | * @param flags Flags describing the key's properties
41 | * @param proto The protocol that the key was created for
42 | * @param alg The key's algorithm
43 | * @param key The key as a PublicKey
44 | * @throws DNSSEC.DNSSECException The PublicKey could not be converted into DNS
45 | * format.
46 | */
47 | public
48 | CDNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
49 | PublicKey key) throws DNSSEC.DNSSECException
50 | {
51 | super(name, Type.CDNSKEY, dclass, ttl, flags, proto, alg,
52 | DNSSEC.fromPublicKey(key, alg));
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/CDSRecord.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: BSD-2-Clause
2 | package fairy.easy.httpmodel.server;
3 |
4 | /**
5 | * Child Delegation Signer record as specified in RFC 8078.
6 | *
7 | * @see DNSSEC
8 | * @see RFC 8078: Managing DS Records from the Parent via CDS/CDNSKEY
9 | */
10 | public class CDSRecord extends DSRecord {
11 |
12 | private static final long serialVersionUID = -3156174257356976006L;
13 |
14 | CDSRecord() {}
15 |
16 | @Override
17 | Record
18 | getObject() {
19 | return new CDSRecord();
20 | }
21 |
22 | /**
23 | * Creates a CDS Record from the given data
24 | * @param footprint The original KEY record's footprint (keyid).
25 | * @param alg The original key algorithm.
26 | * @param digestid The digest id code.
27 | * @param digest A hash of the original key.
28 | */
29 | public
30 | CDSRecord(Name name, int dclass, long ttl, int footprint, int alg,
31 | int digestid, byte [] digest)
32 | {
33 | super(name, Type.CDS, dclass, ttl, footprint, alg, digestid, digest);
34 | }
35 |
36 | /**
37 | * Creates a CDS Record from the given data
38 | * @param digestid The digest id code.
39 | * @param key The key to digest
40 | */
41 | public
42 | CDSRecord(Name name, int dclass, long ttl, int digestid, DNSKEYRecord key)
43 | {
44 | super(name, Type.CDS, dclass, ttl, key.getFootprint(),
45 | key.getAlgorithm(), digestid,
46 | DNSSEC.generateDSDigest(key, digestid));
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/CNAMERecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * CNAME Record - maps an alias to its real name
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 1035: Domain Names - Implementation and Specification
10 | */
11 | public class CNAMERecord extends SingleCompressedNameBase {
12 |
13 | private static final long serialVersionUID = -4020373886892538580L;
14 |
15 | CNAMERecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new CNAMERecord();
21 | }
22 |
23 | /**
24 | * Creates a new CNAMERecord with the given data
25 | * @param alias The name to which the CNAME alias points
26 | */
27 | public
28 | CNAMERecord(Name name, int dclass, long ttl, Name alias) {
29 | super(name, Type.CNAME, dclass, ttl, alias, "alias");
30 | }
31 |
32 | /**
33 | * Gets the target of the CNAME Record
34 | */
35 | public Name
36 | getTarget() {
37 | return getSingleName();
38 | }
39 |
40 | /** Gets the alias specified by the CNAME Record */
41 | public Name
42 | getAlias() {
43 | return getSingleName();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Client.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2005 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 | import java.net.*;
7 | import java.nio.channels.*;
8 |
9 | import fairy.easy.httpmodel.server.utils.hexdump;
10 |
11 |
12 | class Client {
13 |
14 | protected long endTime;
15 | protected SelectionKey key;
16 |
17 | /**
18 | * Packet logger, if available.
19 | */
20 | private static PacketLogger packetLogger = null;
21 |
22 | protected
23 | Client(SelectableChannel channel, long endTime) throws IOException {
24 | boolean done = false;
25 | Selector selector = null;
26 | this.endTime = endTime;
27 | try {
28 | selector = Selector.open();
29 | channel.configureBlocking(false);
30 | key = channel.register(selector, SelectionKey.OP_READ);
31 | done = true;
32 | }
33 | finally {
34 | if (!done && selector != null)
35 | selector.close();
36 | if (!done)
37 | channel.close();
38 | }
39 | }
40 |
41 | static protected void
42 | blockUntil(SelectionKey key, long endTime) throws IOException {
43 | long timeout = endTime - System.currentTimeMillis();
44 | int nkeys = 0;
45 | if (timeout > 0)
46 | nkeys = key.selector().select(timeout);
47 | else if (timeout == 0)
48 | nkeys = key.selector().selectNow();
49 | if (nkeys == 0)
50 | throw new SocketTimeoutException();
51 | }
52 |
53 | static protected void
54 | verboseLog(String prefix, SocketAddress local, SocketAddress remote,
55 | byte [] data)
56 | {
57 | if (Options.check("verbosemsg"))
58 | System.err.println(hexdump.dump(prefix, data));
59 | if (packetLogger != null)
60 | packetLogger.log(prefix, local, remote, data);
61 | }
62 |
63 | void
64 | cleanup() throws IOException {
65 | key.selector().close();
66 | key.channel().close();
67 | }
68 |
69 | static void setPacketLogger(PacketLogger logger)
70 | {
71 | packetLogger = logger;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Compression.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * DNS Name Compression object.
7 | * @see Message
8 | * @see Name
9 | *
10 | * @author Brian Wellington
11 | */
12 |
13 | public class Compression {
14 |
15 | private static class Entry {
16 | Name name;
17 | int pos;
18 | Entry next;
19 | }
20 |
21 | private static final int TABLE_SIZE = 17;
22 | private static final int MAX_POINTER = 0x3FFF;
23 | private Entry [] table;
24 | private boolean verbose = Options.check("verbosecompression");
25 |
26 | /**
27 | * Creates a new Compression object.
28 | */
29 | public
30 | Compression() {
31 | table = new Entry[TABLE_SIZE];
32 | }
33 |
34 | /**
35 | * Adds a compression entry mapping a name to a position in a message.
36 | * @param pos The position at which the name is added.
37 | * @param name The name being added to the message.
38 | */
39 | public void
40 | add(int pos, Name name) {
41 | if (pos > MAX_POINTER)
42 | return;
43 | int row = (name.hashCode() & 0x7FFFFFFF) % TABLE_SIZE;
44 | Entry entry = new Entry();
45 | entry.name = name;
46 | entry.pos = pos;
47 | entry.next = table[row];
48 | table[row] = entry;
49 | if (verbose)
50 | System.err.println("Adding " + name + " at " + pos);
51 | }
52 |
53 | /**
54 | * Retrieves the position of the given name, if it has been previously
55 | * included in the message.
56 | * @param name The name to find in the compression table.
57 | * @return The position of the name, or -1 if not found.
58 | */
59 | public int
60 | get(Name name) {
61 | int row = (name.hashCode() & 0x7FFFFFFF) % TABLE_SIZE;
62 | int pos = -1;
63 | for (Entry entry = table[row]; entry != null; entry = entry.next) {
64 | if (entry.name.equals(name))
65 | pos = entry.pos;
66 | }
67 | if (verbose)
68 | System.err.println("Looking for " + name + ", found " + pos);
69 | return pos;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Credibility.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Constants relating to the credibility of cached data, which is based on
7 | * the data's source. The constants NORMAL and ANY should be used by most
8 | * callers.
9 | * @see Cache
10 | * @see Section
11 | *
12 | * @author Brian Wellington
13 | */
14 |
15 | public final class Credibility {
16 |
17 | private
18 | Credibility() {}
19 |
20 | /** A hint or cache file on disk. */
21 | public static final int HINT = 0;
22 |
23 | /** The additional section of a response. */
24 | public static final int ADDITIONAL = 1;
25 |
26 | /** The additional section of a response. */
27 | public static final int GLUE = 2;
28 |
29 | /** The authority section of a nonauthoritative response. */
30 | public static final int NONAUTH_AUTHORITY = 3;
31 |
32 | /** The answer section of a nonauthoritative response. */
33 | public static final int NONAUTH_ANSWER = 3;
34 |
35 | /** The authority section of an authoritative response. */
36 | public static final int AUTH_AUTHORITY = 4;
37 |
38 | /** The answer section of a authoritative response. */
39 | public static final int AUTH_ANSWER = 4;
40 |
41 | /** A zone. */
42 | public static final int ZONE = 5;
43 |
44 | /** Credible data. */
45 | public static final int NORMAL = 3;
46 |
47 | /** Data not required to be credible. */
48 | public static final int ANY = 1;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/DClass.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Constants and functions relating to DNS classes. This is called DClass
7 | * to avoid confusion with Class.
8 | *
9 | * @author Brian Wellington
10 | */
11 |
12 | public final class DClass {
13 |
14 | /** Internet */
15 | public static final int IN = 1;
16 |
17 | /** Chaos network (MIT) */
18 | public static final int CH = 3;
19 |
20 | /** Chaos network (MIT, alternate name) */
21 | public static final int CHAOS = 3;
22 |
23 | /** Hesiod name server (MIT) */
24 | public static final int HS = 4;
25 |
26 | /** Hesiod name server (MIT, alternate name) */
27 | public static final int HESIOD = 4;
28 |
29 | /** Special value used in dynamic update messages */
30 | public static final int NONE = 254;
31 |
32 | /** Matches any class */
33 | public static final int ANY = 255;
34 |
35 | private static class DClassMnemonic extends Mnemonic {
36 | public
37 | DClassMnemonic() {
38 | super("DClass", CASE_UPPER);
39 | setPrefix("CLASS");
40 | }
41 |
42 | @Override
43 | public void
44 | check(int val) {
45 | DClass.check(val);
46 | }
47 | }
48 |
49 | private static Mnemonic classes = new DClassMnemonic();
50 |
51 | static {
52 | classes.add(IN, "IN");
53 | classes.add(CH, "CH");
54 | classes.addAlias(CH, "CHAOS");
55 | classes.add(HS, "HS");
56 | classes.addAlias(HS, "HESIOD");
57 | classes.add(NONE, "NONE");
58 | classes.add(ANY, "ANY");
59 | }
60 |
61 | private
62 | DClass() {}
63 |
64 | /**
65 | * Checks that a numeric DClass is valid.
66 | * @throws InvalidDClassException The class is out of range.
67 | */
68 | public static void
69 | check(int i) {
70 | if (i < 0 || i > 0xFFFF)
71 | throw new InvalidDClassException(i);
72 | }
73 |
74 | /**
75 | * Converts a numeric DClass into a String
76 | * @return The canonical string representation of the class
77 | * @throws InvalidDClassException The class is out of range.
78 | */
79 | public static String
80 | string(int i) {
81 | return classes.getText(i);
82 | }
83 |
84 | /**
85 | * Converts a String representation of a DClass into its numeric value
86 | * @return The class code, or -1 on error.
87 | */
88 | public static int
89 | value(String s) {
90 | return classes.getValue(s);
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/DHCIDRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2008 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | import fairy.easy.httpmodel.server.utils.base64;
8 |
9 |
10 | /**
11 | * DHCID - Dynamic Host Configuration Protocol (DHCP) ID (RFC 4701)
12 | *
13 | * @author Brian Wellington
14 | * @see RFC 4701: A DNS Resource Record (RR) for Encoding
15 | * Dynamic Host Configuration Protocol (DHCP) Information (DHCID RR)
16 | */
17 | public class DHCIDRecord extends Record {
18 |
19 | private static final long serialVersionUID = -8214820200808997707L;
20 |
21 | private byte [] data;
22 |
23 | DHCIDRecord() {}
24 |
25 | @Override
26 | Record
27 | getObject() {
28 | return new DHCIDRecord();
29 | }
30 |
31 | /**
32 | * Creates an DHCID Record from the given data
33 | * @param data The binary data, which is opaque to DNS.
34 | */
35 | public
36 | DHCIDRecord(Name name, int dclass, long ttl, byte [] data) {
37 | super(name, Type.DHCID, dclass, ttl);
38 | this.data = data;
39 | }
40 |
41 | @Override
42 | void
43 | rrFromWire(DNSInput in) {
44 | data = in.readByteArray();
45 | }
46 |
47 | @Override
48 | void
49 | rdataFromString(Tokenizer st, Name origin) throws IOException {
50 | data = st.getBase64();
51 | }
52 |
53 | @Override
54 | void
55 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
56 | out.writeByteArray(data);
57 | }
58 |
59 | @Override
60 | String
61 | rrToString() {
62 | return base64.toString(data);
63 | }
64 |
65 | /**
66 | * Returns the binary data.
67 | */
68 | public byte []
69 | getData() {
70 | return data;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/DNAMERecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * DNAME Record - maps a nonterminal alias (subtree) to a different domain
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 6672: DNAME Redirection in the DNS
10 | */
11 | public class DNAMERecord extends SingleNameBase {
12 |
13 | private static final long serialVersionUID = 2670767677200844154L;
14 |
15 | DNAMERecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new DNAMERecord();
21 | }
22 |
23 | /**
24 | * Creates a new DNAMERecord with the given data
25 | * @param alias The name to which the DNAME alias points
26 | */
27 | public
28 | DNAMERecord(Name name, int dclass, long ttl, Name alias) {
29 | super(name, Type.DNAME, dclass, ttl, alias, "alias");
30 | }
31 |
32 | /**
33 | * Gets the target of the DNAME Record
34 | */
35 | public Name
36 | getTarget() {
37 | return getSingleName();
38 | }
39 |
40 | /** Gets the alias specified by the DNAME Record */
41 | public Name
42 | getAlias() {
43 | return getSingleName();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/DNSKEYRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 | import java.security.PublicKey;
7 |
8 | /**
9 | * Key - contains a cryptographic public key for use by DNS.
10 | * The data can be converted to objects implementing
11 | * java.security.interfaces.PublicKey
12 | * @see DNSSEC
13 | *
14 | * @author Brian Wellington
15 | * @see RFC 4034: Resource Records for the DNS Security Extensions
16 | */
17 | public class DNSKEYRecord extends KEYBase {
18 |
19 | public static class Protocol {
20 | private Protocol() {}
21 |
22 | /** Key will be used for DNSSEC */
23 | public static final int DNSSEC = 3;
24 | }
25 |
26 | public static class Flags {
27 | private Flags() {}
28 |
29 | /** Key is a zone key */
30 | public static final int ZONE_KEY = 0x100;
31 |
32 | /** Key is a secure entry point key */
33 | public static final int SEP_KEY = 0x1;
34 |
35 | /** Key has been revoked */
36 | public static final int REVOKE = 0x80;
37 | }
38 |
39 | private static final long serialVersionUID = -8679800040426675002L;
40 |
41 | DNSKEYRecord() {}
42 |
43 | @Override
44 | Record
45 | getObject() {
46 | return new DNSKEYRecord();
47 | }
48 |
49 | /**
50 | * Creates a DNSKEY Record from the given data
51 | * @param flags Flags describing the key's properties
52 | * @param proto The protocol that the key was created for
53 | * @param alg The key's algorithm
54 | * @param key Binary representation of the key
55 | */
56 | protected
57 | DNSKEYRecord(Name name, int type, int dclass, long ttl, int flags, int proto,
58 | int alg, byte [] key)
59 | {
60 | super(name, type, dclass, ttl, flags, proto, alg, key);
61 | }
62 |
63 | /**
64 | * Creates a DNSKEY Record from the given data
65 | * @param flags Flags describing the key's properties
66 | * @param proto The protocol that the key was created for
67 | * @param alg The key's algorithm
68 | * @param key Binary representation of the key
69 | */
70 | public
71 | DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
72 | byte [] key)
73 | {
74 | this(name, Type.DNSKEY, dclass, ttl, flags, proto, alg, key);
75 | }
76 |
77 | /**
78 | * Creates a DNSKEY Record from the given data
79 | * @param flags Flags describing the key's properties
80 | * @param proto The protocol that the key was created for
81 | * @param alg The key's algorithm
82 | * @param key The key as a PublicKey
83 | * @throws DNSSEC.DNSSECException The PublicKey could not be converted into DNS
84 | * format.
85 | */
86 | public
87 | DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
88 | PublicKey key) throws DNSSEC.DNSSECException
89 | {
90 | super(name, Type.DNSKEY, dclass, ttl, flags, proto, alg,
91 | DNSSEC.fromPublicKey(key, alg));
92 | publicKey = key;
93 | }
94 |
95 | @Override
96 | void
97 | rdataFromString(Tokenizer st, Name origin) throws IOException {
98 | flags = st.getUInt16();
99 | proto = st.getUInt8();
100 | String algString = st.getString();
101 | alg = DNSSEC.Algorithm.value(algString);
102 | if (alg < 0)
103 | throw st.exception("Invalid algorithm: " + algString);
104 | key = st.getBase64();
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/EmptyRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * A class implementing Records with no data; that is, records used in
7 | * the question section of messages and meta-records in dynamic update.
8 | *
9 | * @author Brian Wellington
10 | */
11 |
12 | class EmptyRecord extends Record {
13 |
14 | private static final long serialVersionUID = 3601852050646429582L;
15 |
16 | EmptyRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new EmptyRecord();
22 | }
23 |
24 | @Override
25 | void
26 | rrFromWire(DNSInput in) {
27 | }
28 |
29 | @Override
30 | void
31 | rdataFromString(Tokenizer st, Name origin) {
32 | }
33 |
34 | @Override
35 | String
36 | rrToString() {
37 | return "";
38 | }
39 |
40 | @Override
41 | void
42 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/ExtendedFlags.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Constants and functions relating to EDNS flags.
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public final class ExtendedFlags {
12 |
13 | private static Mnemonic extflags = new Mnemonic("EDNS Flag",
14 | Mnemonic.CASE_LOWER);
15 |
16 | /** dnssec ok */
17 | public static final int DO = 0x8000;
18 |
19 | static {
20 | extflags.setMaximum(0xFFFF);
21 | extflags.setPrefix("FLAG");
22 | extflags.setNumericAllowed(true);
23 |
24 | extflags.add(DO, "do");
25 | }
26 |
27 | private
28 | ExtendedFlags() {}
29 |
30 | /** Converts a numeric extended flag into a String */
31 | public static String
32 | string(int i) {
33 | return extflags.getText(i);
34 | }
35 |
36 | /**
37 | * Converts a textual representation of an extended flag into its numeric
38 | * value
39 | */
40 | public static int
41 | value(String s) {
42 | return extflags.getValue(s);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Flags.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Constants and functions relating to flags in the DNS header.
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public final class Flags {
12 |
13 | private static Mnemonic flags = new Mnemonic("DNS Header Flag",
14 | Mnemonic.CASE_LOWER);
15 |
16 | /** query/response */
17 | public static final byte QR = 0;
18 |
19 | /** authoritative answer */
20 | public static final byte AA = 5;
21 |
22 | /** truncated */
23 | public static final byte TC = 6;
24 |
25 | /** recursion desired */
26 | public static final byte RD = 7;
27 |
28 | /** recursion available */
29 | public static final byte RA = 8;
30 |
31 | /** authenticated data */
32 | public static final byte AD = 10;
33 |
34 | /** (security) checking disabled */
35 | public static final byte CD = 11;
36 |
37 | /** dnssec ok (extended) */
38 | public static final int DO = ExtendedFlags.DO;
39 |
40 | static {
41 | flags.setMaximum(0xF);
42 | flags.setPrefix("FLAG");
43 | flags.setNumericAllowed(true);
44 |
45 | flags.add(QR, "qr");
46 | flags.add(AA, "aa");
47 | flags.add(TC, "tc");
48 | flags.add(RD, "rd");
49 | flags.add(RA, "ra");
50 | flags.add(AD, "ad");
51 | flags.add(CD, "cd");
52 | }
53 |
54 | private
55 | Flags() {}
56 |
57 | /** Converts a numeric Flag into a String */
58 | public static String
59 | string(int i) {
60 | return flags.getText(i);
61 | }
62 |
63 | /** Converts a String representation of an Flag into its numeric value */
64 | public static int
65 | value(String s) {
66 | return flags.getValue(s);
67 | }
68 |
69 | /**
70 | * Indicates if a bit in the flags field is a flag or not. If it's part of
71 | * the rcode or opcode, it's not.
72 | */
73 | public static boolean
74 | isFlag(int index) {
75 | flags.check(index);
76 | return (index < 1 || index > 4) && (index < 12);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/FormattedTime.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.*;
6 | import java.text.*;
7 |
8 | /**
9 | * Routines for converting time values to and from YYYYMMDDHHMMSS format.
10 | *
11 | * @author Brian Wellington
12 | */
13 | final class FormattedTime {
14 |
15 | private static NumberFormat w2, w4;
16 |
17 | static {
18 | w2 = new DecimalFormat();
19 | w2.setMinimumIntegerDigits(2);
20 |
21 | w4 = new DecimalFormat();
22 | w4.setMinimumIntegerDigits(4);
23 | w4.setGroupingUsed(false);
24 | }
25 |
26 | private
27 | FormattedTime() {}
28 |
29 | /**
30 | * Converts a Date into a formatted string.
31 | * @param date The Date to convert.
32 | * @return The formatted string.
33 | */
34 | public static String
35 | format(Date date) {
36 | Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
37 | StringBuilder sb = new StringBuilder();
38 |
39 | c.setTime(date);
40 | sb.append(w4.format(c.get(Calendar.YEAR)));
41 | sb.append(w2.format(c.get(Calendar.MONTH)+1));
42 | sb.append(w2.format(c.get(Calendar.DAY_OF_MONTH)));
43 | sb.append(w2.format(c.get(Calendar.HOUR_OF_DAY)));
44 | sb.append(w2.format(c.get(Calendar.MINUTE)));
45 | sb.append(w2.format(c.get(Calendar.SECOND)));
46 | return sb.toString();
47 | }
48 |
49 | /**
50 | * Parses a formatted time string into a Date.
51 | * @param s The string, in the form YYYYMMDDHHMMSS.
52 | * @return The Date object.
53 | * @throws TextParseException The string was invalid.
54 | */
55 | public static Date
56 | parse(String s) throws TextParseException {
57 | if (s.length() != 14) {
58 | throw new TextParseException("Invalid time encoding: " + s);
59 | }
60 |
61 | Calendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
62 | c.clear();
63 | try {
64 | int year = Integer.parseInt(s.substring(0, 4));
65 | int month = Integer.parseInt(s.substring(4, 6)) - 1;
66 | int date = Integer.parseInt(s.substring(6, 8));
67 | int hour = Integer.parseInt(s.substring(8, 10));
68 | int minute = Integer.parseInt(s.substring(10, 12));
69 | int second = Integer.parseInt(s.substring(12, 14));
70 | c.set(year, month, date, hour, minute, second);
71 | }
72 | catch (NumberFormatException e) {
73 | throw new TextParseException("Invalid time encoding: " + s);
74 | }
75 | return c.getTime();
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/GenericEDNSOption.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 | package fairy.easy.httpmodel.server;
3 |
4 |
5 | import fairy.easy.httpmodel.server.utils.base16;
6 |
7 | /**
8 | * An EDNSOption with no internal structure.
9 | *
10 | * @author Ming Zhou <mizhou@bnivideo.com>, Beaumaris Networks
11 | * @author Brian Wellington
12 | */
13 | public class GenericEDNSOption extends EDNSOption {
14 |
15 | private byte [] data;
16 |
17 | GenericEDNSOption(int code) {
18 | super(code);
19 | }
20 |
21 | /**
22 | * Construct a generic EDNS option.
23 | * @param data The contents of the option.
24 | */
25 | public
26 | GenericEDNSOption(int code, byte [] data) {
27 | super(code);
28 | this.data = Record.checkByteArrayLength("option data", data, 0xFFFF);
29 | }
30 |
31 | @Override
32 | void
33 | optionFromWire(DNSInput in) {
34 | data = in.readByteArray();
35 | }
36 |
37 | @Override
38 | void
39 | optionToWire(DNSOutput out) {
40 | out.writeByteArray(data);
41 | }
42 |
43 | @Override
44 | String
45 | optionToString() {
46 | return "<" + base16.toString(data) + ">";
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/HINFORecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Host Information - describes the CPU and OS of a host
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 1035: Domain Names - Implementation and Specification
12 | */
13 | public class HINFORecord extends Record {
14 |
15 | private static final long serialVersionUID = -4732870630947452112L;
16 |
17 | private byte [] cpu, os;
18 |
19 | HINFORecord() {}
20 |
21 | @Override
22 | Record
23 | getObject() {
24 | return new HINFORecord();
25 | }
26 |
27 | /**
28 | * Creates an HINFO Record from the given data
29 | * @param cpu A string describing the host's CPU
30 | * @param os A string describing the host's OS
31 | * @throws IllegalArgumentException One of the strings has invalid escapes
32 | */
33 | public
34 | HINFORecord(Name name, int dclass, long ttl, String cpu, String os) {
35 | super(name, Type.HINFO, dclass, ttl);
36 | try {
37 | this.cpu = byteArrayFromString(cpu);
38 | this.os = byteArrayFromString(os);
39 | }
40 | catch (TextParseException e) {
41 | throw new IllegalArgumentException(e.getMessage());
42 | }
43 | }
44 |
45 | @Override
46 | void
47 | rrFromWire(DNSInput in) throws IOException {
48 | cpu = in.readCountedString();
49 | os = in.readCountedString();
50 | }
51 |
52 | @Override
53 | void
54 | rdataFromString(Tokenizer st, Name origin) throws IOException {
55 | try {
56 | cpu = byteArrayFromString(st.getString());
57 | os = byteArrayFromString(st.getString());
58 | }
59 | catch (TextParseException e) {
60 | throw st.exception(e.getMessage());
61 | }
62 | }
63 |
64 | /**
65 | * Returns the host's CPU
66 | */
67 | public String
68 | getCPU() {
69 | return byteArrayToString(cpu, false);
70 | }
71 |
72 | /**
73 | * Returns the host's OS
74 | */
75 | public String
76 | getOS() {
77 | return byteArrayToString(os, false);
78 | }
79 |
80 | @Override
81 | void
82 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
83 | out.writeCountedString(cpu);
84 | out.writeCountedString(os);
85 | }
86 |
87 | /**
88 | * Converts to a string
89 | */
90 | @Override
91 | String
92 | rrToString() {
93 | StringBuilder sb = new StringBuilder();
94 | sb.append(byteArrayToString(cpu, true));
95 | sb.append(" ");
96 | sb.append(byteArrayToString(os, true));
97 | return sb.toString();
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/ISDNRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * ISDN - identifies the ISDN number and subaddress associated with a name.
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 1183: New DNS RR Definitions
12 | */
13 | public class ISDNRecord extends Record {
14 |
15 | private static final long serialVersionUID = -8730801385178968798L;
16 |
17 | private byte [] address;
18 | private byte [] subAddress;
19 |
20 | ISDNRecord() {}
21 |
22 | @Override
23 | Record
24 | getObject() {
25 | return new ISDNRecord();
26 | }
27 |
28 | /**
29 | * Creates an ISDN Record from the given data
30 | * @param address The ISDN number associated with the domain.
31 | * @param subAddress The subaddress, if any.
32 | * @throws IllegalArgumentException One of the strings is invalid.
33 | */
34 | public
35 | ISDNRecord(Name name, int dclass, long ttl, String address, String subAddress) {
36 | super(name, Type.ISDN, dclass, ttl);
37 | try {
38 | this.address = byteArrayFromString(address);
39 | if (subAddress != null)
40 | this.subAddress = byteArrayFromString(subAddress);
41 | }
42 | catch (TextParseException e) {
43 | throw new IllegalArgumentException(e.getMessage());
44 | }
45 | }
46 |
47 | @Override
48 | void
49 | rrFromWire(DNSInput in) throws IOException {
50 | address = in.readCountedString();
51 | if (in.remaining() > 0)
52 | subAddress = in.readCountedString();
53 | }
54 |
55 | @Override
56 | void
57 | rdataFromString(Tokenizer st, Name origin) throws IOException {
58 | try {
59 | address = byteArrayFromString(st.getString());
60 | Tokenizer.Token t = st.get();
61 | if (t.isString()) {
62 | subAddress = byteArrayFromString(t.value);
63 | } else {
64 | st.unget();
65 | }
66 | }
67 | catch (TextParseException e) {
68 | throw st.exception(e.getMessage());
69 | }
70 | }
71 |
72 | /**
73 | * Returns the ISDN number associated with the domain.
74 | */
75 | public String
76 | getAddress() {
77 | return byteArrayToString(address, false);
78 | }
79 |
80 | /**
81 | * Returns the ISDN subaddress, or null if there is none.
82 | */
83 | public String
84 | getSubAddress() {
85 | if (subAddress == null)
86 | return null;
87 | return byteArrayToString(subAddress, false);
88 | }
89 |
90 | @Override
91 | void
92 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
93 | out.writeCountedString(address);
94 | if (subAddress != null)
95 | out.writeCountedString(subAddress);
96 | }
97 |
98 | @Override
99 | String
100 | rrToString() {
101 | StringBuilder sb = new StringBuilder();
102 | sb.append(byteArrayToString(address, true));
103 | if (subAddress != null) {
104 | sb.append(" ");
105 | sb.append(byteArrayToString(subAddress, true));
106 | }
107 | return sb.toString();
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/InvalidDClassException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * An exception thrown when an invalid dclass code is specified.
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public class InvalidDClassException extends IllegalArgumentException {
12 |
13 | public
14 | InvalidDClassException(int dclass) {
15 | super("Invalid DNS class: " + dclass);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/InvalidTTLException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * An exception thrown when an invalid TTL is specified.
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public class InvalidTTLException extends IllegalArgumentException {
12 |
13 | public
14 | InvalidTTLException(long ttl) {
15 | super("Invalid DNS TTL: " + ttl);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/InvalidTypeException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * An exception thrown when an invalid type code is specified.
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public class InvalidTypeException extends IllegalArgumentException {
12 |
13 | public
14 | InvalidTypeException(int type) {
15 | super("Invalid DNS type: " + type);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/KXRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Key Exchange - delegation of authority
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 2230: Key Exchange Delegation Record for the DNS
10 | */
11 | public class KXRecord extends U16NameBase {
12 |
13 | private static final long serialVersionUID = 7448568832769757809L;
14 |
15 | KXRecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new KXRecord();
21 | }
22 |
23 | /**
24 | * Creates a KX Record from the given data
25 | * @param preference The preference of this KX. Records with lower priority
26 | * are preferred.
27 | * @param target The host that authority is delegated to
28 | */
29 | public
30 | KXRecord(Name name, int dclass, long ttl, int preference, Name target) {
31 | super(name, Type.KX, dclass, ttl, preference, "preference",
32 | target, "target");
33 | }
34 |
35 | /** Returns the target of the KX record */
36 | public Name
37 | getTarget() {
38 | return getNameField();
39 | }
40 |
41 | /** Returns the preference of this KX record */
42 | public int
43 | getPreference() {
44 | return getU16Field();
45 | }
46 |
47 | @Override
48 | public Name
49 | getAdditionalName() {
50 | return getNameField();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MBRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Mailbox Record - specifies a host containing a mailbox.
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 883: Domain Names - Implementation and Specification
10 | */
11 | public class MBRecord extends SingleNameBase {
12 |
13 | private static final long serialVersionUID = 532349543479150419L;
14 |
15 | MBRecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new MBRecord();
21 | }
22 |
23 | /**
24 | * Creates a new MB Record with the given data
25 | * @param mailbox The host containing the mailbox for the domain.
26 | */
27 | public
28 | MBRecord(Name name, int dclass, long ttl, Name mailbox) {
29 | super(name, Type.MB, dclass, ttl, mailbox, "mailbox");
30 | }
31 |
32 | /** Gets the mailbox for the domain */
33 | public Name
34 | getMailbox() {
35 | return getSingleName();
36 | }
37 |
38 | @Override
39 | public Name
40 | getAdditionalName() {
41 | return getSingleName();
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MDRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Mail Destination Record - specifies a mail agent which delivers mail
7 | * for a domain (obsolete)
8 | *
9 | * @author Brian Wellington
10 | * @see RFC 973: Domain System Changes and Observations
11 | */
12 | public class MDRecord extends SingleNameBase {
13 |
14 | private static final long serialVersionUID = 5268878603762942202L;
15 |
16 | MDRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new MDRecord();
22 | }
23 |
24 | /**
25 | * Creates a new MD Record with the given data
26 | * @param mailAgent The mail agent that delivers mail for the domain.
27 | */
28 | public
29 | MDRecord(Name name, int dclass, long ttl, Name mailAgent) {
30 | super(name, Type.MD, dclass, ttl, mailAgent, "mail agent");
31 | }
32 |
33 | /** Gets the mail agent for the domain */
34 | public Name
35 | getMailAgent() {
36 | return getSingleName();
37 | }
38 |
39 | @Override
40 | public Name
41 | getAdditionalName() {
42 | return getSingleName();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MFRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Mail Forwarder Record - specifies a mail agent which forwards mail
7 | * for a domain (obsolete)
8 | *
9 | * @author Brian Wellington
10 | * @see RFC 973: Domain System Changes and Observations
11 | */
12 | public class MFRecord extends SingleNameBase {
13 |
14 | private static final long serialVersionUID = -6670449036843028169L;
15 |
16 | MFRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new MFRecord();
22 | }
23 |
24 | /**
25 | * Creates a new MF Record with the given data
26 | * @param mailAgent The mail agent that forwards mail for the domain.
27 | */
28 | public
29 | MFRecord(Name name, int dclass, long ttl, Name mailAgent) {
30 | super(name, Type.MF, dclass, ttl, mailAgent, "mail agent");
31 | }
32 |
33 | /** Gets the mail agent for the domain */
34 | public Name
35 | getMailAgent() {
36 | return getSingleName();
37 | }
38 |
39 | @Override
40 | public Name
41 | getAdditionalName() {
42 | return getSingleName();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MGRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Mail Group Record - specifies a mailbox which is a member of a mail group.
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 883: Domain Names - Implementation and Specification
10 | */
11 | public class MGRecord extends SingleNameBase {
12 |
13 | private static final long serialVersionUID = -3980055550863644582L;
14 |
15 | MGRecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new MGRecord();
21 | }
22 |
23 | /**
24 | * Creates a new MG Record with the given data
25 | * @param mailbox The mailbox that is a member of the group specified by the
26 | * domain.
27 | */
28 | public
29 | MGRecord(Name name, int dclass, long ttl, Name mailbox) {
30 | super(name, Type.MG, dclass, ttl, mailbox, "mailbox");
31 | }
32 |
33 | /** Gets the mailbox in the mail group specified by the domain */
34 | public Name
35 | getMailbox() {
36 | return getSingleName();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MINFORecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Mailbox information Record - lists the address responsible for a mailing
9 | * list/mailbox and the address to receive error messages relating to the
10 | * mailing list/mailbox.
11 | *
12 | * @author Brian Wellington
13 | * @see RFC 883: Domain Names - Implementation and Specification
14 | */
15 | public class MINFORecord extends Record {
16 |
17 | private static final long serialVersionUID = -3962147172340353796L;
18 |
19 | private Name responsibleAddress;
20 | private Name errorAddress;
21 |
22 | MINFORecord() {}
23 |
24 | @Override
25 | Record
26 | getObject() {
27 | return new MINFORecord();
28 | }
29 |
30 | /**
31 | * Creates an MINFO Record from the given data
32 | * @param responsibleAddress The address responsible for the
33 | * mailing list/mailbox.
34 | * @param errorAddress The address to receive error messages relating to the
35 | * mailing list/mailbox.
36 | */
37 | public
38 | MINFORecord(Name name, int dclass, long ttl,
39 | Name responsibleAddress, Name errorAddress)
40 | {
41 | super(name, Type.MINFO, dclass, ttl);
42 |
43 | this.responsibleAddress = checkName("responsibleAddress",
44 | responsibleAddress);
45 | this.errorAddress = checkName("errorAddress", errorAddress);
46 | }
47 |
48 | @Override
49 | void
50 | rrFromWire(DNSInput in) throws IOException {
51 | responsibleAddress = new Name(in);
52 | errorAddress = new Name(in);
53 | }
54 |
55 | @Override
56 | void
57 | rdataFromString(Tokenizer st, Name origin) throws IOException {
58 | responsibleAddress = st.getName(origin);
59 | errorAddress = st.getName(origin);
60 | }
61 |
62 | /** Converts the MINFO Record to a String */
63 | @Override
64 | String
65 | rrToString() {
66 | StringBuilder sb = new StringBuilder();
67 | sb.append(responsibleAddress);
68 | sb.append(" ");
69 | sb.append(errorAddress);
70 | return sb.toString();
71 | }
72 |
73 | /** Gets the address responsible for the mailing list/mailbox. */
74 | public Name
75 | getResponsibleAddress() {
76 | return responsibleAddress;
77 | }
78 |
79 | /**
80 | * Gets the address to receive error messages relating to the mailing
81 | * list/mailbox.
82 | */
83 | public Name
84 | getErrorAddress() {
85 | return errorAddress;
86 | }
87 |
88 | @Override
89 | void
90 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
91 | responsibleAddress.toWire(out, null, canonical);
92 | errorAddress.toWire(out, null, canonical);
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MRRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Mailbox Rename Record - specifies a rename of a mailbox.
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 883: Domain Names - Implementation and Specification
10 | */
11 | public class MRRecord extends SingleNameBase {
12 |
13 | private static final long serialVersionUID = -5617939094209927533L;
14 |
15 | MRRecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new MRRecord();
21 | }
22 |
23 | /**
24 | * Creates a new MR Record with the given data
25 | * @param newName The new name of the mailbox specified by the domain.
26 | * domain.
27 | */
28 | public
29 | MRRecord(Name name, int dclass, long ttl, Name newName) {
30 | super(name, Type.MR, dclass, ttl, newName, "new name");
31 | }
32 |
33 | /** Gets the new name of the mailbox specified by the domain */
34 | public Name
35 | getNewName() {
36 | return getSingleName();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/MXRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Mail Exchange - specifies where mail to a domain is sent
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 1035: Domain Names - Implementation and Specification
10 | * @see RFC 7505: A "Null MX" No Service Resource Record for Domains That Accept No Mail
11 | */
12 | public class MXRecord extends U16NameBase {
13 |
14 | private static final long serialVersionUID = 2914841027584208546L;
15 |
16 | MXRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new MXRecord();
22 | }
23 |
24 | /**
25 | * Creates an MX Record from the given data
26 | * @param priority The priority of this MX. Records with lower priority
27 | * are preferred.
28 | * @param target The host that mail is sent to
29 | */
30 | public
31 | MXRecord(Name name, int dclass, long ttl, int priority, Name target) {
32 | super(name, Type.MX, dclass, ttl, priority, "priority",
33 | target, "target");
34 | }
35 |
36 | /** Returns the target of the MX record */
37 | public Name
38 | getTarget() {
39 | return getNameField();
40 | }
41 |
42 | /** Returns the priority of this MX record */
43 | public int
44 | getPriority() {
45 | return getU16Field();
46 | }
47 |
48 | @Override
49 | void
50 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
51 | out.writeU16(u16Field);
52 | nameField.toWire(out, c, canonical);
53 | }
54 |
55 | @Override
56 | public Name
57 | getAdditionalName() {
58 | return getNameField();
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NSAPRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | import fairy.easy.httpmodel.server.utils.base16;
8 |
9 |
10 | /**
11 | * NSAP Address Record.
12 | *
13 | * @author Brian Wellington
14 | * @see RFC 1706: DNS NSAP Resource Records
15 | */
16 | public class NSAPRecord extends Record {
17 |
18 | private static final long serialVersionUID = -1037209403185658593L;
19 |
20 | private byte [] address;
21 |
22 | NSAPRecord() {}
23 |
24 | @Override
25 | Record
26 | getObject() {
27 | return new NSAPRecord();
28 | }
29 |
30 | private static byte []
31 | checkAndConvertAddress(String address) {
32 | if (!address.substring(0, 2).equalsIgnoreCase("0x")) {
33 | return null;
34 | }
35 | ByteArrayOutputStream bytes = new ByteArrayOutputStream();
36 | boolean partial = false;
37 | int current = 0;
38 | for (int i = 2; i < address.length(); i++) {
39 | char c = address.charAt(i);
40 | if (c == '.') {
41 | continue;
42 | }
43 | int value = Character.digit(c, 16);
44 | if (value == -1) {
45 | return null;
46 | }
47 | if (partial) {
48 | current += value;
49 | bytes.write(current);
50 | partial = false;
51 | } else {
52 | current = value << 4;
53 | partial = true;
54 | }
55 |
56 | }
57 | if (partial) {
58 | return null;
59 | }
60 | return bytes.toByteArray();
61 | }
62 |
63 | /**
64 | * Creates an NSAP Record from the given data
65 | * @param address The NSAP address.
66 | * @throws IllegalArgumentException The address is not a valid NSAP address.
67 | */
68 | public
69 | NSAPRecord(Name name, int dclass, long ttl, String address) {
70 | super(name, Type.NSAP, dclass, ttl);
71 | this.address = checkAndConvertAddress(address);
72 | if (this.address == null) {
73 | throw new IllegalArgumentException("invalid NSAP address " +
74 | address);
75 | }
76 | }
77 |
78 | @Override
79 | void
80 | rrFromWire(DNSInput in) {
81 | address = in.readByteArray();
82 | }
83 |
84 | @Override
85 | void
86 | rdataFromString(Tokenizer st, Name origin) throws IOException {
87 | String addr = st.getString();
88 | this.address = checkAndConvertAddress(addr);
89 | if (this.address == null)
90 | throw st.exception("invalid NSAP address " + addr);
91 | }
92 |
93 | /**
94 | * Returns the NSAP address.
95 | */
96 | public String
97 | getAddress() {
98 | return byteArrayToString(address, false);
99 | }
100 |
101 | @Override
102 | void
103 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
104 | out.writeByteArray(address);
105 | }
106 |
107 | @Override
108 | String
109 | rrToString() {
110 | return "0x" + base16.toString(address);
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NSAP_PTRRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * NSAP Pointer Record - maps a domain name representing an NSAP Address to
7 | * a hostname. (obsolete)
8 | *
9 | * @author Brian Wellington
10 | * @see RFC 1706: DNS NSAP Resource Records
11 | */
12 | public class NSAP_PTRRecord extends SingleNameBase {
13 |
14 | private static final long serialVersionUID = 2386284746382064904L;
15 |
16 | NSAP_PTRRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new NSAP_PTRRecord();
22 | }
23 |
24 | /**
25 | * Creates a new NSAP_PTR Record with the given data
26 | * @param target The name of the host with this address
27 | */
28 | public
29 | NSAP_PTRRecord(Name name, int dclass, long ttl, Name target) {
30 | super(name, Type.NSAP_PTR, dclass, ttl, target, "target");
31 | }
32 |
33 | /** Gets the target of the NSAP_PTR Record */
34 | public Name
35 | getTarget() {
36 | return getSingleName();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NSECRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Next SECure name - this record contains the following name in an
9 | * ordered list of names in the zone, and a set of types for which
10 | * records exist for this name. The presence of this record in a response
11 | * signifies a negative response from a DNSSEC-signed zone.
12 | *
13 | * This replaces the NXT record.
14 | *
15 | * @author Brian Wellington
16 | * @author David Blacka
17 | *
18 | * @see RFC 4034: Resource Records for the DNS Security Extensions
19 | */
20 | public class NSECRecord extends Record {
21 |
22 | private static final long serialVersionUID = -5165065768816265385L;
23 |
24 | private Name next;
25 | private TypeBitmap types;
26 |
27 | NSECRecord() {}
28 |
29 | @Override
30 | Record
31 | getObject() {
32 | return new NSECRecord();
33 | }
34 |
35 | /**
36 | * Creates an NSEC Record from the given data.
37 | * @param next The following name in an ordered list of the zone
38 | * @param types An array containing the types present.
39 | */
40 | public
41 | NSECRecord(Name name, int dclass, long ttl, Name next, int [] types) {
42 | super(name, Type.NSEC, dclass, ttl);
43 | this.next = checkName("next", next);
44 | for (int value : types) {
45 | Type.check(value);
46 | }
47 | this.types = new TypeBitmap(types);
48 | }
49 |
50 | @Override
51 | void
52 | rrFromWire(DNSInput in) throws IOException {
53 | next = new Name(in);
54 | types = new TypeBitmap(in);
55 | }
56 |
57 | @Override
58 | void
59 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
60 | // Note: The next name is not lowercased.
61 | next.toWire(out, null, false);
62 | types.toWire(out);
63 | }
64 |
65 | @Override
66 | void
67 | rdataFromString(Tokenizer st, Name origin) throws IOException {
68 | next = st.getName(origin);
69 | types = new TypeBitmap(st);
70 | }
71 |
72 | /** Converts rdata to a String */
73 | @Override
74 | String
75 | rrToString()
76 | {
77 | StringBuilder sb = new StringBuilder();
78 | sb.append(next);
79 | if (!types.empty()) {
80 | sb.append(' ');
81 | sb.append(types.toString());
82 | }
83 | return sb.toString();
84 | }
85 |
86 | /** Returns the next name */
87 | public Name
88 | getNext() {
89 | return next;
90 | }
91 |
92 | /** Returns the set of types defined for this name */
93 | public int []
94 | getTypes() {
95 | return types.toArray();
96 | }
97 |
98 | /** Returns whether a specific type is in the set of types. */
99 | public boolean
100 | hasType(int type) {
101 | return types.contains(type);
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NSIDOption.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * The Name Server Identifier Option
7 | *
8 | * @see OPTRecord
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 5001: DNS Name Server Identifier (NSID) Option
12 | */
13 | public class NSIDOption extends GenericEDNSOption {
14 |
15 | private static final long serialVersionUID = 74739759292589056L;
16 |
17 | NSIDOption() {
18 | super(EDNSOption.Code.NSID);
19 | }
20 |
21 | /**
22 | * Construct an NSID option.
23 | * @param data The contents of the option.
24 | */
25 | public
26 | NSIDOption(byte [] data) {
27 | super(EDNSOption.Code.NSID, data);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NSRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Name Server Record - contains the name server serving the named zone
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 1035: Domain Names - Implementation and Specification
10 | */
11 | public class NSRecord extends SingleCompressedNameBase {
12 |
13 | private static final long serialVersionUID = 487170758138268838L;
14 |
15 | NSRecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new NSRecord();
21 | }
22 |
23 | /**
24 | * Creates a new NS Record with the given data
25 | * @param target The name server for the given domain
26 | */
27 | public
28 | NSRecord(Name name, int dclass, long ttl, Name target) {
29 | super(name, Type.NS, dclass, ttl, target, "target");
30 | }
31 |
32 | /** Gets the target of the NS Record */
33 | public Name
34 | getTarget() {
35 | return getSingleName();
36 | }
37 |
38 | @Override
39 | public Name
40 | getAdditionalName() {
41 | return getSingleName();
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NULLRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * The NULL Record. This has no defined purpose, but can be used to
9 | * hold arbitrary data.
10 | *
11 | * @author Brian Wellington
12 | * @see RFC 1035: Domain Names - Implementation and Specification
13 | */
14 | public class NULLRecord extends Record {
15 |
16 | private static final long serialVersionUID = -5796493183235216538L;
17 |
18 | private byte [] data;
19 |
20 | NULLRecord() {}
21 |
22 | @Override
23 | Record
24 | getObject() {
25 | return new NULLRecord();
26 | }
27 |
28 | /**
29 | * Creates a NULL record from the given data.
30 | * @param data The contents of the record.
31 | */
32 | public
33 | NULLRecord(Name name, int dclass, long ttl, byte [] data) {
34 | super(name, Type.NULL, dclass, ttl);
35 |
36 | if (data.length > 0xFFFF) {
37 | throw new IllegalArgumentException("data must be <65536 bytes");
38 | }
39 | this.data = data;
40 | }
41 |
42 | @Override
43 | void
44 | rrFromWire(DNSInput in) {
45 | data = in.readByteArray();
46 | }
47 |
48 | @Override
49 | void
50 | rdataFromString(Tokenizer st, Name origin) throws IOException {
51 | throw st.exception("no defined text format for NULL records");
52 | }
53 |
54 | @Override
55 | String
56 | rrToString() {
57 | return unknownToString(data);
58 | }
59 |
60 | /** Returns the contents of this record. */
61 | public byte []
62 | getData() {
63 | return data;
64 | }
65 |
66 | @Override
67 | void
68 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
69 | out.writeByteArray(data);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NXTRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 | import java.util.*;
7 |
8 | /**
9 | * Next name - this record contains the following name in an ordered list
10 | * of names in the zone, and a set of types for which records exist for
11 | * this name. The presence of this record in a response signifies a
12 | * failed query for data in a DNSSEC-signed zone.
13 | *
14 | * @author Brian Wellington
15 | * @see RFC 2065: Domain Name System Security Extensions
16 | */
17 | public class NXTRecord extends Record {
18 |
19 | private static final long serialVersionUID = -8851454400765507520L;
20 |
21 | private Name next;
22 | private BitSet bitmap;
23 |
24 | NXTRecord() {}
25 |
26 | @Override
27 | Record
28 | getObject() {
29 | return new NXTRecord();
30 | }
31 |
32 | /**
33 | * Creates an NXT Record from the given data
34 | * @param next The following name in an ordered list of the zone
35 | * @param bitmap The set of type for which records exist at this name
36 | */
37 | public
38 | NXTRecord(Name name, int dclass, long ttl, Name next, BitSet bitmap) {
39 | super(name, Type.NXT, dclass, ttl);
40 | this.next = checkName("next", next);
41 | this.bitmap = bitmap;
42 | }
43 |
44 | @Override
45 | void
46 | rrFromWire(DNSInput in) throws IOException {
47 | next = new Name(in);
48 | bitmap = new BitSet();
49 | int bitmapLength = in.remaining();
50 | for (int i = 0; i < bitmapLength; i++) {
51 | int t = in.readU8();
52 | for (int j = 0; j < 8; j++)
53 | if ((t & (1 << (7 - j))) != 0)
54 | bitmap.set(i * 8 + j);
55 | }
56 | }
57 |
58 | @Override
59 | void
60 | rdataFromString(Tokenizer st, Name origin) throws IOException {
61 | next = st.getName(origin);
62 | bitmap = new BitSet();
63 | while (true) {
64 | Tokenizer.Token t = st.get();
65 | if (!t.isString())
66 | break;
67 | int typecode = Type.value(t.value, true);
68 | if (typecode <= 0 || typecode > 128)
69 | throw st.exception("Invalid type: " + t.value);
70 | bitmap.set(typecode);
71 | }
72 | st.unget();
73 | }
74 |
75 | /** Converts rdata to a String */
76 | @Override
77 | String
78 | rrToString() {
79 | StringBuilder sb = new StringBuilder();
80 | sb.append(next);
81 | int length = bitmap.length();
82 | for (short i = 0; i < length; i++)
83 | if (bitmap.get(i)) {
84 | sb.append(" ");
85 | sb.append(Type.string(i));
86 | }
87 | return sb.toString();
88 | }
89 |
90 | /** Returns the next name */
91 | public Name
92 | getNext() {
93 | return next;
94 | }
95 |
96 | /** Returns the set of types defined for this name */
97 | public BitSet
98 | getBitmap() {
99 | return bitmap;
100 | }
101 |
102 | @Override
103 | void
104 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
105 | next.toWire(out, null, canonical);
106 | int length = bitmap.length();
107 | for (int i = 0, t = 0; i < length; i++) {
108 | t |= (bitmap.get(i) ? (1 << (7 - i % 8)) : 0);
109 | if (i % 8 == 7 || i == length - 1) {
110 | out.writeU8(t);
111 | t = 0;
112 | }
113 | }
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/NameTooLongException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * An exception thrown when a name is longer than the maximum length of a DNS
7 | * name.
8 | *
9 | * @author Brian Wellington
10 | */
11 |
12 | public class NameTooLongException extends WireParseException {
13 |
14 | public
15 | NameTooLongException() {
16 | super();
17 | }
18 |
19 | public
20 | NameTooLongException(String s) {
21 | super(s);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/OPENPGPKEYRecord.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.server;
2 |
3 | import java.io.IOException;
4 |
5 | import fairy.easy.httpmodel.server.utils.base64;
6 |
7 |
8 | /**
9 | * OPENPGPKEY Record - Stores an OpenPGP certificate associated with a name.
10 | *
11 | * @author Brian Wellington
12 | * @author Valentin Hauner
13 | *
14 | * @see RFC 7929: DNS-Based Authentication of Named Entities (DANE) Bindings for OpenPGP
15 | */
16 | public class OPENPGPKEYRecord extends Record {
17 |
18 | private static final long serialVersionUID = -1277262990243423062L;
19 |
20 | private byte [] cert;
21 |
22 | OPENPGPKEYRecord() {}
23 |
24 | @Override
25 | Record
26 | getObject() {
27 | return new OPENPGPKEYRecord();
28 | }
29 |
30 | /**
31 | * Creates an OPENPGPKEY Record from the given data
32 | *
33 | * @param cert Binary data representing the certificate
34 | */
35 | public
36 | OPENPGPKEYRecord(Name name, int dclass, long ttl, byte [] cert)
37 | {
38 | super(name, Type.OPENPGPKEY, dclass, ttl);
39 | this.cert = cert;
40 | }
41 |
42 | @Override
43 | void
44 | rrFromWire(DNSInput in) {
45 | cert = in.readByteArray();
46 | }
47 |
48 | @Override
49 | void
50 | rdataFromString(Tokenizer st, Name origin) throws IOException {
51 | cert = st.getBase64();
52 | }
53 |
54 | /**
55 | * Converts rdata to a String
56 | */
57 | @Override
58 | String
59 | rrToString() {
60 | StringBuilder sb = new StringBuilder();
61 | if (cert != null) {
62 | if (Options.check("multiline")) {
63 | sb.append("(\n");
64 | sb.append(base64.formatString(cert, 64, "\t", true));
65 | } else {
66 | sb.append(base64.toString(cert));
67 | }
68 | }
69 | return sb.toString();
70 | }
71 |
72 | /**
73 | * Returns the binary representation of the certificate
74 | */
75 | public byte []
76 | getCert()
77 | {
78 | return cert;
79 | }
80 |
81 | @Override
82 | void
83 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
84 | out.writeByteArray(cert);
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Opcode.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Constants and functions relating to DNS opcodes
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public final class Opcode {
12 |
13 | /** A standard query */
14 | public static final int QUERY = 0;
15 |
16 | /** An inverse query (deprecated) */
17 | public static final int IQUERY = 1;
18 |
19 | /** A server status request (not used) */
20 | public static final int STATUS = 2;
21 |
22 | /**
23 | * A message from a primary to a secondary server to initiate a zone transfer
24 | */
25 | public static final int NOTIFY = 4;
26 |
27 | /** A dynamic update message */
28 | public static final int UPDATE = 5;
29 |
30 | private static Mnemonic opcodes = new Mnemonic("DNS Opcode",
31 | Mnemonic.CASE_UPPER);
32 |
33 | static {
34 | opcodes.setMaximum(0xF);
35 | opcodes.setPrefix("RESERVED");
36 | opcodes.setNumericAllowed(true);
37 |
38 | opcodes.add(QUERY, "QUERY");
39 | opcodes.add(IQUERY, "IQUERY");
40 | opcodes.add(STATUS, "STATUS");
41 | opcodes.add(NOTIFY, "NOTIFY");
42 | opcodes.add(UPDATE, "UPDATE");
43 | }
44 |
45 | private
46 | Opcode() {}
47 |
48 | /** Converts a numeric Opcode into a String */
49 | public static String
50 | string(int i) {
51 | return opcodes.getText(i);
52 | }
53 |
54 | /** Converts a String representation of an Opcode into its numeric value */
55 | public static int
56 | value(String s) {
57 | return opcodes.getValue(s);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Options.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * Boolean options:
9 | * bindttl - Print TTLs in BIND format
10 | * multiline - Print records in multiline format
11 | * noprintin - Don't print the class of a record if it's IN
12 | * verbose - Turn on general debugging statements
13 | * verbosemsg - Print all messages sent or received by SimpleResolver
14 | * verbosecompression - Print messages related to name compression
15 | * verbosesec - Print messages related to signature verification
16 | * verbosecache - Print messages related to cache lookups
17 | *
18 | * Valued options:
19 | * tsigfudge=n - Sets the default TSIG fudge value (in seconds)
20 | * sig0validity=n - Sets the default SIG(0) validity period (in seconds)
21 | *
22 | * @author Brian Wellington
23 | */
24 |
25 | public final class Options {
26 |
27 | private static Map table;
28 |
29 | static {
30 | try {
31 | refresh();
32 | }
33 | catch (SecurityException e) {
34 | }
35 | }
36 |
37 | private
38 | Options() {}
39 |
40 | public static void
41 | refresh() {
42 | String s = System.getProperty("dnsjava.options");
43 | if (s != null) {
44 | StringTokenizer st = new StringTokenizer(s, ",");
45 | while (st.hasMoreTokens()) {
46 | String token = st.nextToken();
47 | int index = token.indexOf('=');
48 | if (index == -1)
49 | set(token);
50 | else {
51 | String option = token.substring(0, index);
52 | String value = token.substring(index + 1);
53 | set(option, value);
54 | }
55 | }
56 | }
57 | }
58 |
59 | /** Clears all defined options */
60 | public static void
61 | clear() {
62 | table = null;
63 | }
64 |
65 | /** Sets an option to "true" */
66 | public static void
67 | set(String option) {
68 | if (table == null)
69 | table = new HashMap<>();
70 | table.put(option.toLowerCase(), "true");
71 | }
72 |
73 | /** Sets an option to the the supplied value */
74 | public static void
75 | set(String option, String value) {
76 | if (table == null)
77 | table = new HashMap<>();
78 | table.put(option.toLowerCase(), value.toLowerCase());
79 | }
80 |
81 | /** Removes an option */
82 | public static void
83 | unset(String option) {
84 | if (table == null)
85 | return;
86 | table.remove(option.toLowerCase());
87 | }
88 |
89 | /** Checks if an option is defined */
90 | public static boolean
91 | check(String option) {
92 | if (table == null)
93 | return false;
94 | return (table.get(option.toLowerCase()) != null);
95 | }
96 |
97 | /** Returns the value of an option */
98 | public static String
99 | value(String option) {
100 | if (table == null)
101 | return null;
102 | return (table.get(option.toLowerCase()));
103 | }
104 |
105 | /**
106 | * Returns the value of an option as an integer, or -1 if not defined.
107 | */
108 | public static int
109 | intValue(String option) {
110 | String s = value(option);
111 | if (s != null) {
112 | try {
113 | int val = Integer.parseInt(s);
114 | if (val > 0)
115 | return (val);
116 | }
117 | catch (NumberFormatException e) {
118 | }
119 | }
120 | return (-1);
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/PTRRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Pointer Record - maps a domain name representing an Internet Address to
7 | * a hostname.
8 | *
9 | * @author Brian Wellington
10 | * @see RFC 1035: Domain Names - Implementation and Specification
11 | */
12 | public class PTRRecord extends SingleCompressedNameBase {
13 |
14 | private static final long serialVersionUID = -8321636610425434192L;
15 |
16 | PTRRecord() {}
17 |
18 | @Override
19 | Record
20 | getObject() {
21 | return new PTRRecord();
22 | }
23 |
24 | /**
25 | * Creates a new PTR Record with the given data
26 | * @param target The name of the machine with this address
27 | */
28 | public
29 | PTRRecord(Name name, int dclass, long ttl, Name target) {
30 | super(name, Type.PTR, dclass, ttl, target, "target");
31 | }
32 |
33 | /** Gets the target of the PTR Record */
34 | public Name
35 | getTarget() {
36 | return getSingleName();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/PXRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * X.400 mail mapping record.
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 2163: Using the Internet DNS to Distribute
12 | * MIXER Conformant Global Address Mapping (MCGAM)
13 | */
14 | public class PXRecord extends Record {
15 |
16 | private static final long serialVersionUID = 1811540008806660667L;
17 |
18 | private int preference;
19 | private Name map822;
20 | private Name mapX400;
21 |
22 | PXRecord() {}
23 |
24 | @Override
25 | Record
26 | getObject() {
27 | return new PXRecord();
28 | }
29 |
30 | /**
31 | * Creates an PX Record from the given data
32 | * @param preference The preference of this mail address.
33 | * @param map822 The RFC 822 component of the mail address.
34 | * @param mapX400 The X.400 component of the mail address.
35 | */
36 | public
37 | PXRecord(Name name, int dclass, long ttl, int preference,
38 | Name map822, Name mapX400)
39 | {
40 | super(name, Type.PX, dclass, ttl);
41 |
42 | this.preference = checkU16("preference", preference);
43 | this.map822 = checkName("map822", map822);
44 | this.mapX400 = checkName("mapX400", mapX400);
45 | }
46 |
47 | @Override
48 | void
49 | rrFromWire(DNSInput in) throws IOException {
50 | preference = in.readU16();
51 | map822 = new Name(in);
52 | mapX400 = new Name(in);
53 | }
54 |
55 | @Override
56 | void
57 | rdataFromString(Tokenizer st, Name origin) throws IOException {
58 | preference = st.getUInt16();
59 | map822 = st.getName(origin);
60 | mapX400 = st.getName(origin);
61 | }
62 |
63 | /** Converts the PX Record to a String */
64 | @Override
65 | String
66 | rrToString() {
67 | StringBuilder sb = new StringBuilder();
68 | sb.append(preference);
69 | sb.append(" ");
70 | sb.append(map822);
71 | sb.append(" ");
72 | sb.append(mapX400);
73 | return sb.toString();
74 | }
75 |
76 | @Override
77 | void
78 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
79 | out.writeU16(preference);
80 | map822.toWire(out, null, canonical);
81 | mapX400.toWire(out, null, canonical);
82 | }
83 |
84 | /** Gets the preference of the route. */
85 | public int
86 | getPreference() {
87 | return preference;
88 | }
89 |
90 | /** Gets the RFC 822 component of the mail address. */
91 | public Name
92 | getMap822() {
93 | return map822;
94 | }
95 |
96 | /** Gets the X.400 component of the mail address. */
97 | public Name
98 | getMapX400() {
99 | return mapX400;
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/PacketLogger.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.server;
2 |
3 | import java.net.*;
4 |
5 | /**
6 | * Custom logger that can log all the packets that were send or received.
7 | * @author Damian Minkov
8 | */
9 | public interface PacketLogger {
10 | void log(String prefix, SocketAddress local, SocketAddress remote,
11 | byte[] data);
12 | }
13 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/RPRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Responsible Person Record - lists the mail address of a responsible person
9 | * and a domain where TXT records are available.
10 | *
11 | * @author Tom Scola (tscola@research.att.com)
12 | * @author Brian Wellington
13 | *
14 | * @see RFC 1183: New DNS RR Definitions
15 | */
16 | public class RPRecord extends Record {
17 |
18 | private static final long serialVersionUID = 8124584364211337460L;
19 |
20 | private Name mailbox;
21 | private Name textDomain;
22 |
23 | RPRecord() {}
24 |
25 | @Override
26 | Record
27 | getObject() {
28 | return new RPRecord();
29 | }
30 |
31 | /**
32 | * Creates an RP Record from the given data
33 | * @param mailbox The responsible person
34 | * @param textDomain The address where TXT records can be found
35 | */
36 | public
37 | RPRecord(Name name, int dclass, long ttl, Name mailbox, Name textDomain) {
38 | super(name, Type.RP, dclass, ttl);
39 |
40 | this.mailbox = checkName("mailbox", mailbox);
41 | this.textDomain = checkName("textDomain", textDomain);
42 | }
43 |
44 | @Override
45 | void
46 | rrFromWire(DNSInput in) throws IOException {
47 | mailbox = new Name(in);
48 | textDomain = new Name(in);
49 | }
50 |
51 | @Override
52 | void
53 | rdataFromString(Tokenizer st, Name origin) throws IOException {
54 | mailbox = st.getName(origin);
55 | textDomain = st.getName(origin);
56 | }
57 |
58 | /** Converts the RP Record to a String */
59 | @Override
60 | String
61 | rrToString() {
62 | StringBuilder sb = new StringBuilder();
63 | sb.append(mailbox);
64 | sb.append(" ");
65 | sb.append(textDomain);
66 | return sb.toString();
67 | }
68 |
69 | /** Gets the mailbox address of the RP Record */
70 | public Name
71 | getMailbox() {
72 | return mailbox;
73 | }
74 |
75 | /** Gets the text domain info of the RP Record */
76 | public Name
77 | getTextDomain() {
78 | return textDomain;
79 | }
80 |
81 | @Override
82 | void
83 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
84 | mailbox.toWire(out, null, canonical);
85 | textDomain.toWire(out, null, canonical);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/RRSIGRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * Resource Record Signature - An RRSIG provides the digital signature of an
9 | * RRset, so that the data can be authenticated by a DNSSEC-capable resolver.
10 | * The signature is generated by a key contained in a DNSKEY Record.
11 | * @see RRset
12 | * @see DNSSEC
13 | * @see KEYRecord
14 | * @see RFC 4034: Resource Records for the DNS Security Extensions
15 | *
16 | * @author Brian Wellington
17 | */
18 | public class RRSIGRecord extends SIGBase {
19 |
20 | private static final long serialVersionUID = -2609150673537226317L;
21 |
22 | RRSIGRecord() {}
23 |
24 | @Override
25 | Record
26 | getObject() {
27 | return new RRSIGRecord();
28 | }
29 |
30 | /**
31 | * Creates an RRSIG Record from the given data
32 | * @param covered The RRset type covered by this signature
33 | * @param alg The cryptographic algorithm of the key that generated the
34 | * signature
35 | * @param origttl The original TTL of the RRset
36 | * @param expire The time at which the signature expires
37 | * @param timeSigned The time at which this signature was generated
38 | * @param footprint The footprint/key id of the signing key.
39 | * @param signer The owner of the signing key
40 | * @param signature Binary data representing the signature
41 | */
42 | public
43 | RRSIGRecord(Name name, int dclass, long ttl, int covered, int alg, long origttl,
44 | Date expire, Date timeSigned, int footprint, Name signer,
45 | byte [] signature)
46 | {
47 | super(name, Type.RRSIG, dclass, ttl, covered, alg, origttl, expire,
48 | timeSigned, footprint, signer, signature);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/RTRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Route Through Record - lists a route preference and intermediate host.
7 | *
8 | * @author Brian Wellington
9 | * @see RFC 1035: Domain Names - Implementation and Specification
10 | */
11 | public class RTRecord extends U16NameBase {
12 |
13 | private static final long serialVersionUID = -3206215651648278098L;
14 |
15 | RTRecord() {}
16 |
17 | @Override
18 | Record
19 | getObject() {
20 | return new RTRecord();
21 | }
22 |
23 | /**
24 | * Creates an RT Record from the given data
25 | * @param preference The preference of the route. Smaller numbers indicate
26 | * more preferred routes.
27 | * @param intermediateHost The domain name of the host to use as a router.
28 | */
29 | public
30 | RTRecord(Name name, int dclass, long ttl, int preference,
31 | Name intermediateHost)
32 | {
33 | super(name, Type.RT, dclass, ttl, preference, "preference",
34 | intermediateHost, "intermediateHost");
35 | }
36 |
37 | /** Gets the preference of the route. */
38 | public int
39 | getPreference() {
40 | return getU16Field();
41 | }
42 |
43 | /** Gets the host to use as a router. */
44 | public Name
45 | getIntermediateHost() {
46 | return getNameField();
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/RelativeNameException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * An exception thrown when a relative name is passed as an argument to
7 | * a method requiring an absolute name.
8 | *
9 | * @author Brian Wellington
10 | */
11 |
12 | public class RelativeNameException extends IllegalArgumentException {
13 |
14 | public
15 | RelativeNameException(Name name) {
16 | super("'" + name + "' is not an absolute name");
17 | }
18 |
19 | public
20 | RelativeNameException(String s) {
21 | super(s);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/ResolveThread.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * A special-purpose thread used by Resolvers (both SimpleResolver and
7 | * ExtendedResolver) to perform asynchronous queries.
8 | *
9 | * @author Brian Wellington
10 | */
11 |
12 | class ResolveThread extends Thread {
13 |
14 | private Message query;
15 | private Integer id;
16 | private ResolverListener listener;
17 | private Resolver res;
18 |
19 | /** Creates a new ResolveThread */
20 | public
21 | ResolveThread(Resolver res, Message query, Integer id,
22 | ResolverListener listener)
23 | {
24 | this.res = res;
25 | this.query = query;
26 | this.id = id;
27 | this.listener = listener;
28 | }
29 |
30 |
31 | /**
32 | * Performs the query, and executes the callback.
33 | */
34 | @Override
35 | public void
36 | run() {
37 | try {
38 | Message response = res.send(query);
39 | listener.receiveMessage(id, response);
40 | }
41 | catch (Exception e) {
42 | listener.handleException(id, e);
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Resolver.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 | import java.util.*;
7 |
8 | /**
9 | * Interface describing a resolver.
10 | *
11 | * @author Brian Wellington
12 | */
13 |
14 | public interface Resolver {
15 |
16 | /**
17 | * Sets the port to communicate with on the server
18 | * @param port The port to send messages to
19 | */
20 | void setPort(int port);
21 |
22 | /**
23 | * Sets whether TCP connections will be sent by default
24 | * @param flag Indicates whether TCP connections are made
25 | */
26 | void setTCP(boolean flag);
27 |
28 | /**
29 | * Sets whether truncated responses will be ignored. If not, a truncated
30 | * response over UDP will cause a retransmission over TCP.
31 | * @param flag Indicates whether truncated responses should be ignored.
32 | */
33 | void setIgnoreTruncation(boolean flag);
34 |
35 | /**
36 | * Sets the EDNS version used on outgoing messages.
37 | * @param level The EDNS level to use. 0 indicates EDNS0 and -1 indicates no
38 | * EDNS.
39 | * @throws IllegalArgumentException An invalid level was indicated.
40 | */
41 | void setEDNS(int level);
42 |
43 | /**
44 | * Sets the EDNS information on outgoing messages.
45 | * @param level The EDNS level to use. 0 indicates EDNS0 and -1 indicates no
46 | * EDNS.
47 | * @param payloadSize The maximum DNS packet size that this host is capable
48 | * of receiving over UDP. If 0 is specified, the default (1280) is used.
49 | * @param flags EDNS extended flags to be set in the OPT record.
50 | * @param options EDNS options to be set in the OPT record, specified as a
51 | * List of OPTRecord.Option elements.
52 | * @throws IllegalArgumentException An invalid field was specified.
53 | * @see OPTRecord
54 | */
55 | void setEDNS(int level, int payloadSize, int flags, List options);
56 |
57 | /**
58 | * Specifies the TSIG key that messages will be signed with
59 | * @param key The key
60 | */
61 | void setTSIGKey(TSIG key);
62 |
63 | /**
64 | * Sets the amount of time to wait for a response before giving up.
65 | * @param secs The number of seconds to wait.
66 | * @param msecs The number of milliseconds to wait.
67 | */
68 | void setTimeout(int secs, int msecs);
69 |
70 | /**
71 | * Sets the amount of time to wait for a response before giving up.
72 | * @param secs The number of seconds to wait.
73 | */
74 | void setTimeout(int secs);
75 |
76 | /**
77 | * Sends a message and waits for a response.
78 | * @param query The query to send.
79 | * @return The response
80 | * @throws IOException An error occurred while sending or receiving.
81 | */
82 | Message send(Message query) throws IOException;
83 |
84 | /**
85 | * Asynchronously sends a message registering a listener to receive a callback
86 | * on success or exception. Multiple asynchronous lookups can be performed
87 | * in parallel. Since the callback may be invoked before the function returns,
88 | * external synchronization is necessary.
89 | * @param query The query to send
90 | * @param listener The object containing the callbacks.
91 | * @return An identifier, which is also a parameter in the callback
92 | */
93 | Object sendAsync(final Message query, final ResolverListener listener);
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/ResolverListener.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.EventListener;
6 |
7 | /**
8 | * An interface to the asynchronous resolver.
9 | * @see Resolver
10 | *
11 | * @author Brian Wellington
12 | */
13 |
14 | public interface ResolverListener extends EventListener {
15 |
16 | /**
17 | * The callback used by an asynchronous resolver
18 | * @param id The identifier returned by Resolver.sendAsync()
19 | * @param m The response message as returned by the Resolver
20 | */
21 | void receiveMessage(Object id, Message m);
22 |
23 | /**
24 | * The callback used by an asynchronous resolver when an exception is thrown
25 | * @param id The identifier returned by Resolver.sendAsync()
26 | * @param e The thrown exception
27 | */
28 | void handleException(Object id, Exception e);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SIG0.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2001-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.security.PrivateKey;
6 | import java.util.Date;
7 |
8 | /**
9 | * Creates SIG(0) transaction signatures.
10 | *
11 | * @author Pasi Eronen
12 | * @author Brian Wellington
13 | */
14 |
15 | public class SIG0 {
16 |
17 | /**
18 | * The default validity period for outgoing SIG(0) signed messages.
19 | * Can be overriden by the sig0validity option.
20 | */
21 | private static final short VALIDITY = 300;
22 |
23 | private
24 | SIG0() { }
25 |
26 | /**
27 | * Sign a message with SIG(0). The DNS key and private key must refer to the
28 | * same underlying cryptographic key.
29 | * @param message The message to be signed
30 | * @param key The DNSKEY record to use as part of signing
31 | * @param privkey The PrivateKey to use when signing
32 | * @param previous If this message is a response, the SIG(0) from the query
33 | */
34 | public static void
35 | signMessage(Message message, KEYRecord key, PrivateKey privkey,
36 | SIGRecord previous) throws DNSSEC.DNSSECException
37 | {
38 |
39 | int validity = Options.intValue("sig0validity");
40 | if (validity < 0)
41 | validity = VALIDITY;
42 |
43 | long now = System.currentTimeMillis();
44 | Date timeSigned = new Date(now);
45 | Date timeExpires = new Date(now + validity * 1000);
46 |
47 | SIGRecord sig = DNSSEC.signMessage(message, previous, key, privkey,
48 | timeSigned, timeExpires);
49 |
50 | message.addRecord(sig, Section.ADDITIONAL);
51 | }
52 |
53 | /**
54 | * Verify a message using SIG(0).
55 | * @param message The message to be signed
56 | * @param b An array containing the message in unparsed form. This is
57 | * necessary since SIG(0) signs the message in wire format, and we can't
58 | * recreate the exact wire format (with the same name compression).
59 | * @param key The KEY record to verify the signature with.
60 | * @param previous If this message is a response, the SIG(0) from the query
61 | */
62 | public static void
63 | verifyMessage(Message message, byte [] b, KEYRecord key, SIGRecord previous)
64 | throws DNSSEC.DNSSECException
65 | {
66 | SIGRecord sig = null;
67 | Record[] additional = message.getSectionArray(Section.ADDITIONAL);
68 | for (Record record : additional) {
69 | if (record.getType() != Type.SIG)
70 | continue;
71 | if (((SIGRecord) record).getTypeCovered() != 0)
72 | continue;
73 | sig = (SIGRecord) record;
74 | break;
75 | }
76 | DNSSEC.verifyMessage(message, b, sig, previous, key);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SIGRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * Signature - A SIG provides the digital signature of an RRset, so that
9 | * the data can be authenticated by a DNSSEC-capable resolver. The
10 | * signature is usually generated by a key contained in a KEYRecord
11 | * @see RRset
12 | * @see DNSSEC
13 | * @see KEYRecord
14 | * RFC 2535: Domain Name System Security Extensions
15 | *
16 | * @author Brian Wellington
17 | */
18 | public class SIGRecord extends SIGBase {
19 |
20 | private static final long serialVersionUID = 4963556060953589058L;
21 |
22 | SIGRecord() {}
23 |
24 | @Override
25 | Record
26 | getObject() {
27 | return new SIGRecord();
28 | }
29 |
30 | /**
31 | * Creates an SIG Record from the given data
32 | * @param covered The RRset type covered by this signature
33 | * @param alg The cryptographic algorithm of the key that generated the
34 | * signature
35 | * @param origttl The original TTL of the RRset
36 | * @param expire The time at which the signature expires
37 | * @param timeSigned The time at which this signature was generated
38 | * @param footprint The footprint/key id of the signing key.
39 | * @param signer The owner of the signing key
40 | * @param signature Binary data representing the signature
41 | */
42 | public
43 | SIGRecord(Name name, int dclass, long ttl, int covered, int alg, long origttl,
44 | Date expire, Date timeSigned, int footprint, Name signer,
45 | byte [] signature)
46 | {
47 | super(name, Type.SIG, dclass, ttl, covered, alg, origttl, expire,
48 | timeSigned, footprint, signer, signature);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SPFRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * Sender Policy Framework (discontinued in RFC 7208)
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 7208: Sender Policy Framework (SPF)
12 | * for Authorizing Use of Domains in Email, Version 1
13 | */
14 | public class SPFRecord extends TXTBase {
15 |
16 | private static final long serialVersionUID = -2100754352801658722L;
17 |
18 | SPFRecord() {}
19 |
20 | @Override
21 | Record
22 | getObject() {
23 | return new SPFRecord();
24 | }
25 |
26 | /**
27 | * Creates a SPF Record from the given data
28 | * @param strings The text strings
29 | * @throws IllegalArgumentException One of the strings has invalid escapes
30 | */
31 | public
32 | SPFRecord(Name name, int dclass, long ttl, List strings) {
33 | super(name, Type.SPF, dclass, ttl, strings);
34 | }
35 |
36 | /**
37 | * Creates a SPF Record from the given data
38 | * @param string One text string
39 | * @throws IllegalArgumentException The string has invalid escapes
40 | */
41 | public
42 | SPFRecord(Name name, int dclass, long ttl, String string) {
43 | super(name, Type.SPF, dclass, ttl, string);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SRVRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Server Selection Record - finds hosts running services in a domain. An
9 | * SRV record will normally be named _<service>._<protocol>.domain
10 | * - examples would be _sips._tcp.example.org (for the secure SIP protocol) and
11 | * _http._tcp.example.com (if HTTP used SRV records)
12 | *
13 | * @author Brian Wellington
14 | * @see RFC 2782: A DNS RR for specifying the location of services (DNS SRV)
15 | */
16 | public class SRVRecord extends Record {
17 |
18 | private static final long serialVersionUID = -3886460132387522052L;
19 |
20 | private int priority, weight, port;
21 | private Name target;
22 |
23 | SRVRecord() {}
24 |
25 | @Override
26 | Record
27 | getObject() {
28 | return new SRVRecord();
29 | }
30 |
31 | /**
32 | * Creates an SRV Record from the given data
33 | * @param priority The priority of this SRV. Records with lower priority
34 | * are preferred.
35 | * @param weight The weight, used to select between records at the same
36 | * priority.
37 | * @param port The TCP/UDP port that the service uses
38 | * @param target The host running the service
39 | */
40 | public
41 | SRVRecord(Name name, int dclass, long ttl, int priority,
42 | int weight, int port, Name target)
43 | {
44 | super(name, Type.SRV, dclass, ttl);
45 | this.priority = checkU16("priority", priority);
46 | this.weight = checkU16("weight", weight);
47 | this.port = checkU16("port", port);
48 | this.target = checkName("target", target);
49 | }
50 |
51 | @Override
52 | void
53 | rrFromWire(DNSInput in) throws IOException {
54 | priority = in.readU16();
55 | weight = in.readU16();
56 | port = in.readU16();
57 | target = new Name(in);
58 | }
59 |
60 | @Override
61 | void
62 | rdataFromString(Tokenizer st, Name origin) throws IOException {
63 | priority = st.getUInt16();
64 | weight = st.getUInt16();
65 | port = st.getUInt16();
66 | target = st.getName(origin);
67 | }
68 |
69 | /** Converts rdata to a String */
70 | @Override
71 | String
72 | rrToString() {
73 | StringBuilder sb = new StringBuilder();
74 | sb.append(priority).append(" ");
75 | sb.append(weight).append(" ");
76 | sb.append(port).append(" ");
77 | sb.append(target);
78 | return sb.toString();
79 | }
80 |
81 | /** Returns the priority */
82 | public int
83 | getPriority() {
84 | return priority;
85 | }
86 |
87 | /** Returns the weight */
88 | public int
89 | getWeight() {
90 | return weight;
91 | }
92 |
93 | /** Returns the port that the service runs on */
94 | public int
95 | getPort() {
96 | return port;
97 | }
98 |
99 | /** Returns the host running that the service */
100 | public Name
101 | getTarget() {
102 | return target;
103 | }
104 |
105 | @Override
106 | void
107 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
108 | out.writeU16(priority);
109 | out.writeU16(weight);
110 | out.writeU16(port);
111 | target.toWire(out, null, canonical);
112 | }
113 |
114 | @Override
115 | public Name
116 | getAdditionalName() {
117 | return target;
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SSHFPRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | import fairy.easy.httpmodel.server.utils.base16;
8 |
9 |
10 | /**
11 | * SSH Fingerprint - stores the fingerprint of an SSH host key.
12 | *
13 | * @author Brian Wellington
14 | * @see RFC 4255: Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
15 | */
16 | public class SSHFPRecord extends Record {
17 |
18 | private static final long serialVersionUID = -8104701402654687025L;
19 |
20 | public static class Algorithm {
21 | private Algorithm() {}
22 |
23 | public static final int RSA = 1;
24 | public static final int DSS = 2;
25 | }
26 |
27 | public static class Digest {
28 | private Digest() {}
29 |
30 | public static final int SHA1 = 1;
31 | }
32 |
33 | private int alg;
34 | private int digestType;
35 | private byte [] fingerprint;
36 |
37 | SSHFPRecord() {}
38 |
39 | @Override
40 | Record
41 | getObject() {
42 | return new SSHFPRecord();
43 | }
44 |
45 | /**
46 | * Creates an SSHFP Record from the given data.
47 | * @param alg The public key's algorithm.
48 | * @param digestType The public key's digest type.
49 | * @param fingerprint The public key's fingerprint.
50 | */
51 | public
52 | SSHFPRecord(Name name, int dclass, long ttl, int alg, int digestType,
53 | byte [] fingerprint)
54 | {
55 | super(name, Type.SSHFP, dclass, ttl);
56 | this.alg = checkU8("alg", alg);
57 | this.digestType = checkU8("digestType", digestType);
58 | this.fingerprint = fingerprint;
59 | }
60 |
61 | @Override
62 | void
63 | rrFromWire(DNSInput in) throws IOException {
64 | alg = in.readU8();
65 | digestType = in.readU8();
66 | fingerprint = in.readByteArray();
67 | }
68 |
69 | @Override
70 | void
71 | rdataFromString(Tokenizer st, Name origin) throws IOException {
72 | alg = st.getUInt8();
73 | digestType = st.getUInt8();
74 | fingerprint = st.getHex(true);
75 | }
76 |
77 | @Override
78 | String
79 | rrToString() {
80 | StringBuilder sb = new StringBuilder();
81 | sb.append(alg);
82 | sb.append(" ");
83 | sb.append(digestType);
84 | sb.append(" ");
85 | sb.append(base16.toString(fingerprint));
86 | return sb.toString();
87 | }
88 |
89 | /** Returns the public key's algorithm. */
90 | public int
91 | getAlgorithm() {
92 | return alg;
93 | }
94 |
95 | /** Returns the public key's digest type. */
96 | public int
97 | getDigestType() {
98 | return digestType;
99 | }
100 |
101 | /** Returns the fingerprint */
102 | public byte []
103 | getFingerPrint() {
104 | return fingerprint;
105 | }
106 |
107 | @Override
108 | void
109 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
110 | out.writeU8(alg);
111 | out.writeU8(digestType);
112 | out.writeByteArray(fingerprint);
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Section.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Constants and functions relating to DNS message sections
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public final class Section {
12 |
13 | /** The question (first) section */
14 | public static final int QUESTION = 0;
15 |
16 | /** The answer (second) section */
17 | public static final int ANSWER = 1;
18 |
19 | /** The authority (third) section */
20 | public static final int AUTHORITY = 2;
21 |
22 | /** The additional (fourth) section */
23 | public static final int ADDITIONAL = 3;
24 |
25 | /* Aliases for dynamic update */
26 | /** The zone (first) section of a dynamic update message */
27 | public static final int ZONE = 0;
28 |
29 | /** The prerequisite (second) section of a dynamic update message */
30 | public static final int PREREQ = 1;
31 |
32 | /** The update (third) section of a dynamic update message */
33 | public static final int UPDATE = 2;
34 |
35 | private static Mnemonic sections = new Mnemonic("Message Section",
36 | Mnemonic.CASE_LOWER);
37 | private static String [] longSections = new String[4];
38 | private static String [] updateSections = new String[4];
39 |
40 | static {
41 | sections.setMaximum(3);
42 | sections.setNumericAllowed(true);
43 |
44 | sections.add(QUESTION, "qd");
45 | sections.add(ANSWER, "an");
46 | sections.add(AUTHORITY, "au");
47 | sections.add(ADDITIONAL, "ad");
48 |
49 | longSections[QUESTION] = "QUESTIONS";
50 | longSections[ANSWER] = "ANSWERS";
51 | longSections[AUTHORITY] = "AUTHORITY RECORDS";
52 | longSections[ADDITIONAL] = "ADDITIONAL RECORDS";
53 |
54 | updateSections[ZONE] = "ZONE";
55 | updateSections[PREREQ] = "PREREQUISITES";
56 | updateSections[UPDATE] = "UPDATE RECORDS";
57 | updateSections[ADDITIONAL] = "ADDITIONAL RECORDS";
58 | }
59 |
60 | private
61 | Section() {}
62 |
63 | /** Converts a numeric Section into an abbreviation String */
64 | public static String
65 | string(int i) {
66 | return sections.getText(i);
67 | }
68 |
69 | /** Converts a numeric Section into a full description String */
70 | public static String
71 | longString(int i) {
72 | sections.check(i);
73 | return longSections[i];
74 | }
75 |
76 | /**
77 | * Converts a numeric Section into a full description String for an update
78 | * Message.
79 | */
80 | public static String
81 | updString(int i) {
82 | sections.check(i);
83 | return updateSections[i];
84 | }
85 |
86 | /** Converts a String representation of a Section into its numeric value */
87 | public static int
88 | value(String s) {
89 | return sections.getValue(s);
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/Serial.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Helper functions for doing serial arithmetic. These should be used when
7 | * setting/checking SOA serial numbers. SOA serial number arithmetic is
8 | * defined in RFC 1982.
9 | *
10 | * @author Brian Wellington
11 | */
12 |
13 | public final class Serial {
14 |
15 | private static final long MAX32 = 0xFFFFFFFFL;
16 |
17 | private
18 | Serial() {
19 | }
20 |
21 | /**
22 | * Compares two numbers using serial arithmetic. The numbers are assumed
23 | * to be 32 bit unsigned integers stored in longs.
24 | * @param serial1 The first integer
25 | * @param serial2 The second integer
26 | * @return 0 if the 2 numbers are equal, a positive number if serial1 is greater
27 | * than serial2, and a negative number if serial2 is greater than serial1.
28 | * @throws IllegalArgumentException serial1 or serial2 is out of range
29 | */
30 | public static int
31 | compare(long serial1, long serial2) {
32 | if (serial1 < 0 || serial1 > MAX32)
33 | throw new IllegalArgumentException(serial1 + " out of range");
34 | if (serial2 < 0 || serial2 > MAX32)
35 | throw new IllegalArgumentException(serial2 + " out of range");
36 | long diff = serial1 - serial2;
37 | if (diff >= MAX32)
38 | diff -= (MAX32 + 1);
39 | else if (diff < -MAX32)
40 | diff += (MAX32 + 1);
41 | return (int)diff;
42 | }
43 |
44 | /**
45 | * Increments a serial number. The number is assumed to be a 32 bit unsigned
46 | * integer stored in a long. This basically adds 1 and resets the value to
47 | * 0 if it is 2^32.
48 | * @param serial The serial number
49 | * @return The incremented serial number
50 | * @throws IllegalArgumentException serial is out of range
51 | */
52 | public static long
53 | increment(long serial) {
54 | if (serial < 0 || serial > MAX32)
55 | throw new IllegalArgumentException(serial + " out of range");
56 | if (serial == MAX32)
57 | return 0;
58 | return serial + 1;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SingleCompressedNameBase.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Implements common functionality for the many record types whose format
7 | * is a single compressed name.
8 | *
9 | * @author Brian Wellington
10 | */
11 |
12 | abstract class SingleCompressedNameBase extends SingleNameBase {
13 |
14 | private static final long serialVersionUID = -236435396815460677L;
15 |
16 | protected
17 | SingleCompressedNameBase() {}
18 |
19 | protected
20 | SingleCompressedNameBase(Name name, int type, int dclass, long ttl,
21 | Name singleName, String description)
22 | {
23 | super(name, type, dclass, ttl, singleName, description);
24 | }
25 |
26 | @Override
27 | void
28 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
29 | singleName.toWire(out, c, canonical);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/SingleNameBase.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Implements common functionality for the many record types whose format
9 | * is a single name.
10 | *
11 | * @author Brian Wellington
12 | */
13 |
14 | abstract class SingleNameBase extends Record {
15 |
16 | private static final long serialVersionUID = -18595042501413L;
17 |
18 | protected Name singleName;
19 |
20 | protected
21 | SingleNameBase() {}
22 |
23 | protected
24 | SingleNameBase(Name name, int type, int dclass, long ttl) {
25 | super(name, type, dclass, ttl);
26 | }
27 |
28 | protected
29 | SingleNameBase(Name name, int type, int dclass, long ttl, Name singleName,
30 | String description)
31 | {
32 | super(name, type, dclass, ttl);
33 | this.singleName = checkName(description, singleName);
34 | }
35 |
36 | @Override
37 | void
38 | rrFromWire(DNSInput in) throws IOException {
39 | singleName = new Name(in);
40 | }
41 |
42 | @Override
43 | void
44 | rdataFromString(Tokenizer st, Name origin) throws IOException {
45 | singleName = st.getName(origin);
46 | }
47 |
48 | @Override
49 | String
50 | rrToString() {
51 | return singleName.toString();
52 | }
53 |
54 | protected Name
55 | getSingleName() {
56 | return singleName;
57 | }
58 |
59 | @Override
60 | void
61 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
62 | singleName.toWire(out, null, canonical);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/TTL.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * Routines for parsing BIND-style TTL values. These values consist of
7 | * numbers followed by 1 letter units of time (W - week, D - day, H - hour,
8 | * M - minute, S - second).
9 | *
10 | * @author Brian Wellington
11 | */
12 |
13 | public final class TTL {
14 |
15 | public static final long MAX_VALUE = 0x7FFFFFFFL;
16 |
17 | private
18 | TTL() {}
19 |
20 | static void
21 | check(long i) {
22 | if (i < 0 || i > MAX_VALUE)
23 | throw new InvalidTTLException(i);
24 | }
25 |
26 | /**
27 | * Parses a TTL-like value, which can either be expressed as a number or a
28 | * BIND-style string with numbers and units.
29 | * @param s The string representing the numeric value.
30 | * @param clamp Whether to clamp values in the range [MAX_VALUE + 1, 2^32 -1]
31 | * to MAX_VALUE. This should be donw for TTLs, but not other values which
32 | * can be expressed in this format.
33 | * @return The value as a number of seconds
34 | * @throws NumberFormatException The string was not in a valid TTL format.
35 | */
36 | public static long
37 | parse(String s, boolean clamp) {
38 | if (s == null || s.length() == 0 || !Character.isDigit(s.charAt(0)))
39 | throw new NumberFormatException();
40 | long value = 0;
41 | long ttl = 0;
42 | for (int i = 0; i < s.length(); i++) {
43 | char c = s.charAt(i);
44 | long oldvalue = value;
45 | if (Character.isDigit(c)) {
46 | value = (value * 10) + Character.getNumericValue(c);
47 | if (value < oldvalue)
48 | throw new NumberFormatException();
49 | } else {
50 | switch (Character.toUpperCase(c)) {
51 | case 'W': value *= 7;
52 | case 'D': value *= 24;
53 | case 'H': value *= 60;
54 | case 'M': value *= 60;
55 | case 'S': break;
56 | default: throw new NumberFormatException();
57 | }
58 | ttl += value;
59 | value = 0;
60 | if (ttl > 0xFFFFFFFFL)
61 | throw new NumberFormatException();
62 | }
63 | }
64 | if (ttl == 0)
65 | ttl = value;
66 |
67 | if (ttl > 0xFFFFFFFFL)
68 | throw new NumberFormatException();
69 | else if (ttl > MAX_VALUE && clamp)
70 | ttl = MAX_VALUE;
71 | return ttl;
72 | }
73 |
74 | /**
75 | * Parses a TTL, which can either be expressed as a number or a BIND-style
76 | * string with numbers and units.
77 | * @param s The string representing the TTL
78 | * @return The TTL as a number of seconds
79 | * @throws NumberFormatException The string was not in a valid TTL format.
80 | */
81 | public static long
82 | parseTTL(String s) {
83 | return parse(s, true);
84 | }
85 |
86 | public static String
87 | format(long ttl) {
88 | TTL.check(ttl);
89 | StringBuilder sb = new StringBuilder();
90 | long secs, mins, hours, days, weeks;
91 | secs = ttl % 60;
92 | ttl /= 60;
93 | mins = ttl % 60;
94 | ttl /= 60;
95 | hours = ttl % 24;
96 | ttl /= 24;
97 | days = ttl % 7;
98 | ttl /= 7;
99 | weeks = ttl;
100 | if (weeks > 0)
101 | sb.append(weeks).append("W");
102 | if (days > 0)
103 | sb.append(days).append("D");
104 | if (hours > 0)
105 | sb.append(hours).append("H");
106 | if (mins > 0)
107 | sb.append(mins).append("M");
108 | if (secs > 0 || (weeks == 0 && days == 0 && hours == 0 && mins == 0))
109 | sb.append(secs).append("S");
110 | return sb.toString();
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/TXTBase.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 | import java.util.*;
7 |
8 | /**
9 | * Implements common functionality for the many record types whose format
10 | * is a list of strings.
11 | *
12 | * @author Brian Wellington
13 | */
14 |
15 | abstract class TXTBase extends Record {
16 |
17 | private static final long serialVersionUID = -4319510507246305931L;
18 |
19 | protected List strings;
20 |
21 | protected
22 | TXTBase() {}
23 |
24 | protected
25 | TXTBase(Name name, int type, int dclass, long ttl) {
26 | super(name, type, dclass, ttl);
27 | }
28 |
29 | protected
30 | TXTBase(Name name, int type, int dclass, long ttl, List strings) {
31 | super(name, type, dclass, ttl);
32 | if (strings == null)
33 | throw new IllegalArgumentException("strings must not be null");
34 | this.strings = new ArrayList<>(strings.size());
35 | Iterator it = strings.iterator();
36 | try {
37 | while (it.hasNext()) {
38 | String s = it.next();
39 | this.strings.add(byteArrayFromString(s));
40 | }
41 | }
42 | catch (TextParseException e) {
43 | throw new IllegalArgumentException(e.getMessage());
44 | }
45 | }
46 |
47 | protected
48 | TXTBase(Name name, int type, int dclass, long ttl, String string) {
49 | this(name, type, dclass, ttl, Collections.singletonList(string));
50 | }
51 |
52 | @Override
53 | void
54 | rrFromWire(DNSInput in) throws IOException {
55 | strings = new ArrayList<>(2);
56 | while (in.remaining() > 0) {
57 | byte[] b = in.readCountedString();
58 | strings.add(b);
59 | }
60 | }
61 |
62 | @Override
63 | void
64 | rdataFromString(Tokenizer st, Name origin) throws IOException {
65 | strings = new ArrayList<>(2);
66 | while (true) {
67 | Tokenizer.Token t = st.get();
68 | if (!t.isString())
69 | break;
70 | try {
71 | strings.add(byteArrayFromString(t.value));
72 | }
73 | catch (TextParseException e) {
74 | throw st.exception(e.getMessage());
75 | }
76 |
77 | }
78 | st.unget();
79 | }
80 |
81 | /** converts to a String */
82 | @Override
83 | String
84 | rrToString() {
85 | StringBuilder sb = new StringBuilder();
86 | Iterator it = strings.iterator();
87 | while (it.hasNext()) {
88 | byte[] array = it.next();
89 | sb.append(byteArrayToString(array, true));
90 | if (it.hasNext())
91 | sb.append(" ");
92 | }
93 | return sb.toString();
94 | }
95 |
96 | /**
97 | * Returns the text strings
98 | * @return A list of Strings corresponding to the text strings.
99 | */
100 | public List
101 | getStrings() {
102 | List list = new ArrayList<>(strings.size());
103 | for (byte[] string : strings)
104 | list.add(byteArrayToString(string, false));
105 | return list;
106 | }
107 |
108 | /**
109 | * Returns the text strings
110 | * @return A list of byte arrays corresponding to the text strings.
111 | */
112 | public List
113 | getStringsAsByteArrays() {
114 | return strings;
115 | }
116 |
117 | @Override
118 | void
119 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
120 | for (byte[] b : strings) {
121 | out.writeCountedString(b);
122 | }
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/TXTRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.util.*;
6 |
7 | /**
8 | * Text - stores text strings
9 | *
10 | * @author Brian Wellington
11 | * @see RFC 1035: Domain Names - Implementation and Specification
12 | */
13 | public class TXTRecord extends TXTBase {
14 |
15 | private static final long serialVersionUID = -5780785764284221342L;
16 |
17 | TXTRecord() {}
18 |
19 | @Override
20 | Record
21 | getObject() {
22 | return new TXTRecord();
23 | }
24 |
25 | /**
26 | * Creates a TXT Record from the given data
27 | * @param strings The text strings
28 | * @throws IllegalArgumentException One of the strings has invalid escapes
29 | */
30 | public
31 | TXTRecord(Name name, int dclass, long ttl, List strings) {
32 | super(name, Type.TXT, dclass, ttl, strings);
33 | }
34 |
35 | /**
36 | * Creates a TXT Record from the given data
37 | * @param string One text string
38 | * @throws IllegalArgumentException The string has invalid escapes
39 | */
40 | public
41 | TXTRecord(Name name, int dclass, long ttl, String string) {
42 | super(name, Type.TXT, dclass, ttl, string);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/TextParseException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * An exception thrown when unable to parse text.
9 | *
10 | * @author Brian Wellington
11 | */
12 |
13 | public class TextParseException extends IOException {
14 |
15 | public
16 | TextParseException() {
17 | super();
18 | }
19 |
20 | public
21 | TextParseException(String s) {
22 | super(s);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/U16NameBase.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Implements common functionality for the many record types whose format
9 | * is an unsigned 16 bit integer followed by a name.
10 | *
11 | * @author Brian Wellington
12 | */
13 |
14 | abstract class U16NameBase extends Record {
15 |
16 | private static final long serialVersionUID = -8315884183112502995L;
17 |
18 | protected int u16Field;
19 | protected Name nameField;
20 |
21 | protected
22 | U16NameBase() {}
23 |
24 | protected
25 | U16NameBase(Name name, int type, int dclass, long ttl) {
26 | super(name, type, dclass, ttl);
27 | }
28 |
29 | protected
30 | U16NameBase(Name name, int type, int dclass, long ttl, int u16Field,
31 | String u16Description, Name nameField, String nameDescription)
32 | {
33 | super(name, type, dclass, ttl);
34 | this.u16Field = checkU16(u16Description, u16Field);
35 | this.nameField = checkName(nameDescription, nameField);
36 | }
37 |
38 | @Override
39 | void
40 | rrFromWire(DNSInput in) throws IOException {
41 | u16Field = in.readU16();
42 | nameField = new Name(in);
43 | }
44 |
45 | @Override
46 | void
47 | rdataFromString(Tokenizer st, Name origin) throws IOException {
48 | u16Field = st.getUInt16();
49 | nameField = st.getName(origin);
50 | }
51 |
52 | @Override
53 | String
54 | rrToString() {
55 | StringBuilder sb = new StringBuilder();
56 | sb.append(u16Field);
57 | sb.append(" ");
58 | sb.append(nameField);
59 | return sb.toString();
60 | }
61 |
62 | protected int
63 | getU16Field() {
64 | return u16Field;
65 | }
66 |
67 | protected Name
68 | getNameField() {
69 | return nameField;
70 | }
71 |
72 | @Override
73 | void
74 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
75 | out.writeU16(u16Field);
76 | nameField.toWire(out, null, canonical);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/UNKRecord.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * A class implementing Records of unknown and/or unimplemented types. This
9 | * class can only be initialized using static Record initializers.
10 | *
11 | * @author Brian Wellington
12 | */
13 | public class UNKRecord extends Record {
14 |
15 | private static final long serialVersionUID = -4193583311594626915L;
16 |
17 | private byte [] data;
18 |
19 | UNKRecord() {}
20 |
21 | @Override
22 | Record
23 | getObject() {
24 | return new UNKRecord();
25 | }
26 |
27 | @Override
28 | void
29 | rrFromWire(DNSInput in) {
30 | data = in.readByteArray();
31 | }
32 |
33 | @Override
34 | void
35 | rdataFromString(Tokenizer st, Name origin) throws IOException {
36 | throw st.exception("invalid unknown RR encoding");
37 | }
38 |
39 | /** Converts this Record to the String "unknown format" */
40 | @Override
41 | String
42 | rrToString() {
43 | return unknownToString(data);
44 | }
45 |
46 | /** Returns the contents of this record. */
47 | public byte []
48 | getData() {
49 | return data;
50 | }
51 |
52 | @Override
53 | void
54 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
55 | out.writeByteArray(data);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/URIRecord.java:
--------------------------------------------------------------------------------
1 | // Implemented by Anthony Kirby (anthony@anthony.org)
2 | // based on SRVRecord.java Copyright (c) 1999-2004 Brian Wellington
3 |
4 | package fairy.easy.httpmodel.server;
5 |
6 | import java.io.*;
7 |
8 | /**
9 | * Uniform Resource Identifier (URI) DNS Resource Record
10 | *
11 | * @author Anthony Kirby
12 | * @see RFC 7553: The Uniform Resource Identifier (URI) DNS Resource Record
13 | */
14 | public class URIRecord extends Record {
15 |
16 | private static final long serialVersionUID = 7955422413971804232L;
17 |
18 | private int priority, weight;
19 | private byte[] target;
20 |
21 | URIRecord() {
22 | target = new byte[]{};
23 | }
24 |
25 | @Override
26 | Record
27 | getObject() {
28 | return new URIRecord();
29 | }
30 |
31 | /**
32 | * Creates a URI Record from the given data
33 | * @param priority The priority of this URI. Records with lower priority
34 | * are preferred.
35 | * @param weight The weight, used to select between records at the same
36 | * priority.
37 | * @param target The host/port running the service
38 | */
39 | public
40 | URIRecord(Name name, int dclass, long ttl, int priority,
41 | int weight, String target)
42 | {
43 | super(name, Type.URI, dclass, ttl);
44 | this.priority = checkU16("priority", priority);
45 | this.weight = checkU16("weight", weight);
46 | try {
47 | this.target = byteArrayFromString(target);
48 | }
49 | catch (TextParseException e) {
50 | throw new IllegalArgumentException(e.getMessage());
51 | }
52 | }
53 |
54 | @Override
55 | void
56 | rrFromWire(DNSInput in) throws IOException {
57 | priority = in.readU16();
58 | weight = in.readU16();
59 | target = in.readByteArray();
60 | }
61 |
62 | @Override
63 | void
64 | rdataFromString(Tokenizer st, Name origin) throws IOException {
65 | priority = st.getUInt16();
66 | weight = st.getUInt16();
67 | try {
68 | target = byteArrayFromString(st.getString());
69 | }
70 | catch (TextParseException e) {
71 | throw st.exception(e.getMessage());
72 | }
73 | }
74 |
75 | /** Converts rdata to a String */
76 | @Override
77 | String
78 | rrToString() {
79 | StringBuilder sb = new StringBuilder();
80 | sb.append(priority).append(" ");
81 | sb.append(weight).append(" ");
82 | sb.append(byteArrayToString(target, true));
83 | return sb.toString();
84 | }
85 |
86 | /** Returns the priority */
87 | public int
88 | getPriority() {
89 | return priority;
90 | }
91 |
92 | /** Returns the weight */
93 | public int
94 | getWeight() {
95 | return weight;
96 | }
97 |
98 | /** Returns the target URI */
99 | public String
100 | getTarget() {
101 | return byteArrayToString(target, false);
102 | }
103 |
104 | @Override
105 | void
106 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
107 | out.writeU16(priority);
108 | out.writeU16(weight);
109 | out.writeByteArray(target);
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/WireParseException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * An exception thrown when a DNS message is invalid.
9 | *
10 | * @author Brian Wellington
11 | */
12 |
13 | public class WireParseException extends IOException {
14 |
15 | public
16 | WireParseException() {
17 | super();
18 | }
19 |
20 | public
21 | WireParseException(String s) {
22 | super(s);
23 | }
24 |
25 | public
26 | WireParseException(String s, Throwable cause) {
27 | super(s);
28 | initCause(cause);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/X25Record.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * X25 - identifies the PSDN (Public Switched Data Network) address in the
9 | * X.121 numbering plan associated with a name.
10 | *
11 | * @author Brian Wellington
12 | * @see RFC 1183: New DNS RR Definitions
13 | */
14 | public class X25Record extends Record {
15 |
16 | private static final long serialVersionUID = 4267576252335579764L;
17 |
18 | private byte [] address;
19 |
20 | X25Record() {}
21 |
22 | @Override
23 | Record
24 | getObject() {
25 | return new X25Record();
26 | }
27 |
28 | private static byte []
29 | checkAndConvertAddress(String address) {
30 | int length = address.length();
31 | byte [] out = new byte [length];
32 | for (int i = 0; i < length; i++) {
33 | char c = address.charAt(i);
34 | if (!Character.isDigit(c))
35 | return null;
36 | out[i] = (byte) c;
37 | }
38 | return out;
39 | }
40 |
41 | /**
42 | * Creates an X25 Record from the given data
43 | * @param address The X.25 PSDN address.
44 | * @throws IllegalArgumentException The address is not a valid PSDN address.
45 | */
46 | public
47 | X25Record(Name name, int dclass, long ttl, String address) {
48 | super(name, Type.X25, dclass, ttl);
49 | this.address = checkAndConvertAddress(address);
50 | if (this.address == null) {
51 | throw new IllegalArgumentException("invalid PSDN address " +
52 | address);
53 | }
54 | }
55 |
56 | @Override
57 | void
58 | rrFromWire(DNSInput in) throws IOException {
59 | address = in.readCountedString();
60 | }
61 |
62 | @Override
63 | void
64 | rdataFromString(Tokenizer st, Name origin) throws IOException {
65 | String addr = st.getString();
66 | this.address = checkAndConvertAddress(addr);
67 | if (this.address == null)
68 | throw st.exception("invalid PSDN address " + addr);
69 | }
70 |
71 | /**
72 | * Returns the X.25 PSDN address.
73 | */
74 | public String
75 | getAddress() {
76 | return byteArrayToString(address, false);
77 | }
78 |
79 | @Override
80 | void
81 | rrToWire(DNSOutput out, Compression c, boolean canonical) {
82 | out.writeCountedString(address);
83 | }
84 |
85 | @Override
86 | String
87 | rrToString() {
88 | return byteArrayToString(address, true);
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/ZoneTransferException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2003-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server;
4 |
5 | /**
6 | * An exception thrown when a zone transfer fails.
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public class ZoneTransferException extends Exception {
12 |
13 | public
14 | ZoneTransferException() {
15 | super();
16 | }
17 |
18 | public
19 | ZoneTransferException(String s) {
20 | super(s);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/utils/base16.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server.utils;
4 |
5 | import java.io.*;
6 |
7 | /**
8 | * Routines for converting between Strings of hex-encoded data and arrays of
9 | * binary data. This is not actually used by DNS.
10 | *
11 | * @author Brian Wellington
12 | */
13 |
14 | public class base16 {
15 |
16 | private static final String Base16 = "0123456789ABCDEF";
17 |
18 | private base16() {
19 | }
20 |
21 | /**
22 | * Convert binary data to a hex-encoded String
23 | *
24 | * @param b An array containing binary data
25 | * @return A String containing the encoded data
26 | */
27 | public static String
28 | toString(byte[] b) {
29 | ByteArrayOutputStream os = new ByteArrayOutputStream();
30 |
31 | for (byte item : b) {
32 | short value = (short) (item & 0xFF);
33 | byte high = (byte) (value >> 4);
34 | byte low = (byte) (value & 0xF);
35 | os.write(Base16.charAt(high));
36 | os.write(Base16.charAt(low));
37 | }
38 | return new String(os.toByteArray());
39 | }
40 |
41 | /**
42 | * Convert a hex-encoded String to binary data
43 | *
44 | * @param str A String containing the encoded data
45 | * @return An array containing the binary data, or null if the string is invalid
46 | */
47 | public static byte[]
48 | fromString(String str) {
49 | ByteArrayOutputStream bs = new ByteArrayOutputStream();
50 | byte[] raw = str.getBytes();
51 | for (byte b : raw) {
52 | if (!Character.isWhitespace((char) b))
53 | bs.write(b);
54 | }
55 | byte[] in = bs.toByteArray();
56 | if (in.length % 2 != 0) {
57 | return null;
58 | }
59 |
60 | bs.reset();
61 | DataOutputStream ds = new DataOutputStream(bs);
62 |
63 | for (int i = 0; i < in.length; i += 2) {
64 | byte high = (byte) Base16.indexOf(Character.toUpperCase((char) in[i]));
65 | byte low = (byte) Base16.indexOf(Character.toUpperCase((char) in[i + 1]));
66 | try {
67 | ds.writeByte((high << 4) + low);
68 | } catch (IOException e) {
69 | }
70 | }
71 | return bs.toByteArray();
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/server/utils/hexdump.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 |
3 | package fairy.easy.httpmodel.server.utils;
4 |
5 | /**
6 | * A routine to produce a nice looking hex dump
7 | *
8 | * @author Brian Wellington
9 | */
10 |
11 | public class hexdump {
12 |
13 | private static final char[] hex = "0123456789ABCDEF".toCharArray();
14 |
15 | /**
16 | * Dumps a byte array into hex format.
17 | *
18 | * @param description If not null, a description of the data.
19 | * @param b The data to be printed.
20 | * @param offset The start of the data in the array.
21 | * @param length The length of the data in the array.
22 | */
23 | public static String
24 | dump(String description, byte[] b, int offset, int length) {
25 | StringBuilder sb = new StringBuilder();
26 |
27 | sb.append(length).append("b");
28 | if (description != null)
29 | sb.append(" (").append(description).append(")");
30 | sb.append(':');
31 |
32 | int prefixlen = sb.toString().length();
33 | prefixlen = (prefixlen + 8) & ~7;
34 | sb.append('\t');
35 |
36 | int perline = (80 - prefixlen) / 3;
37 | for (int i = 0; i < length; i++) {
38 | if (i != 0 && i % perline == 0) {
39 | sb.append('\n');
40 | for (int j = 0; j < prefixlen / 8; j++)
41 | sb.append('\t');
42 | }
43 | int value = (int) (b[i + offset]) & 0xFF;
44 | sb.append(hex[(value >> 4)]);
45 | sb.append(hex[(value & 0xF)]);
46 | sb.append(' ');
47 | }
48 | sb.append('\n');
49 | return sb.toString();
50 | }
51 |
52 | public static String
53 | dump(String s, byte[] b) {
54 | return dump(s, b, 0, b.length);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/Base.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import java.net.MalformedURLException;
4 | import java.net.URL;
5 |
6 | import fairy.easy.httpmodel.HttpModelHelper;
7 |
8 | public class Base {
9 |
10 | public static boolean checkUrl(String address) {
11 | try {
12 | URL url = new URL(address);
13 | return true;
14 | } catch (MalformedURLException e) {
15 | e.printStackTrace();
16 | }
17 | return false;
18 | }
19 |
20 |
21 | public static String getUrlHost() {
22 | String address = HttpModelHelper.getInstance().getAddress();
23 | try {
24 | URL urlStr = new URL(address);
25 | return urlStr.getHost();
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | return address;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/Date.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 |
6 | public class Date {
7 |
8 | /**
9 | * 将时间转换为时间戳
10 | */
11 | public static String dateToStamp(String time) throws ParseException {
12 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
13 | java.util.Date date = simpleDateFormat.parse(time);
14 | long ts = date.getTime();
15 | return String.valueOf(ts);
16 | }
17 |
18 | /**
19 | * 将时间戳转换为时间
20 | */
21 | public static String stampToDate(long timeMillis) {
22 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
23 | java.util.Date date = new java.util.Date(timeMillis);
24 | return simpleDateFormat.format(date);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/Host.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 |
4 | import java.io.BufferedReader;
5 | import java.io.FileReader;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import fairy.easy.httpmodel.resource.base.BaseData;
10 | import fairy.easy.httpmodel.resource.host.HostBean;
11 |
12 |
13 | public class Host {
14 |
15 | public static HostBean getLocalHost() {
16 | HostBean hostBean = new HostBean();
17 | List list = new ArrayList<>();
18 | String mapsFilename = "/system/etc/hosts";
19 | try {
20 | BufferedReader reader = new BufferedReader(new FileReader(mapsFilename));
21 | String line;
22 | while ((line = reader.readLine()) != null) {
23 | list.add(line);
24 | }
25 | reader.close();
26 | hostBean.setStatus(BaseData.HTTP_SUCCESS);
27 | } catch (Exception e) {
28 | hostBean.setStatus(BaseData.HTTP_ERROR);
29 | e.printStackTrace();
30 | }
31 | hostBean.setParam(list);
32 | return hostBean;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/HttpLog.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 |
4 | import android.util.Log;
5 |
6 |
7 | public class HttpLog {
8 | public static final int VERBOSE = 1;
9 | public static final int DEBUG = 2;
10 | public static final int INFO = 3;
11 | public static final int WARN = 4;
12 | public static final int ERROR = 5;
13 | public static final int NOTHING = 6;
14 | public static int LEVEL = VERBOSE;
15 |
16 | public static String TAG = "http_model";
17 |
18 | public static void init(int level, String tag) {
19 | LEVEL = level;
20 | TAG = tag;
21 | }
22 |
23 | public static void v(String msg) {
24 | if (LEVEL <= VERBOSE) {
25 | Log.v(TAG, msg);
26 | }
27 | }
28 |
29 | public static void d(String msg) {
30 | if (LEVEL <= DEBUG) {
31 | Log.d(TAG, msg);
32 | }
33 | }
34 |
35 | public static void i(String msg) {
36 | if (LEVEL <= INFO) {
37 | Log.i(TAG, msg);
38 | }
39 | }
40 |
41 | public static void w(String msg) {
42 | if (LEVEL <= WARN) {
43 | Log.w(TAG, msg);
44 | }
45 | }
46 |
47 | public static void e(String msg) {
48 | if (LEVEL <= ERROR) {
49 | Log.e(TAG, msg);
50 | }
51 | }
52 |
53 | public static void v(String tag, String msg) {
54 | if (LEVEL <= VERBOSE) {
55 | Log.v(tag, msg);
56 | }
57 | }
58 |
59 | public static void d(String tag, String msg) {
60 | if (LEVEL <= DEBUG) {
61 | Log.d(tag, msg);
62 | }
63 | }
64 |
65 | public static void i(String tag, String msg) {
66 | if (LEVEL <= INFO) {
67 | Log.i(tag, msg);
68 | }
69 | }
70 |
71 | public static void w(String tag, String msg) {
72 | if (LEVEL <= WARN) {
73 | Log.w(tag, msg);
74 | }
75 | }
76 |
77 | public static void e(String tag, String msg) {
78 | if (LEVEL <= ERROR) {
79 | Log.e(tag, msg);
80 | }
81 | }
82 | }
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/LogTime.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import android.annotation.TargetApi;
4 | import android.os.Build;
5 | import android.os.SystemClock;
6 |
7 | /**
8 | * A class for logging elapsed real time in millis.
9 | */
10 | public final class LogTime {
11 | private static final double MILLIS_MULTIPLIER =
12 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? 1d / Math.pow(10, 6) : 1d;
13 |
14 | private LogTime() {
15 | // Utility class.
16 | }
17 |
18 | /**
19 | * Returns the current time in either millis or nanos depending on the api level to be used with
20 | * {@link #getElapsedMillis(long)}.
21 | */
22 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
23 | public static long getLogTime() {
24 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
25 | return SystemClock.elapsedRealtimeNanos();
26 | } else {
27 | return SystemClock.uptimeMillis();
28 | }
29 | }
30 |
31 | /**
32 | * Returns the time elapsed since the given logTime in millis.
33 | *
34 | * @param logTime The start time of the event.
35 | */
36 | public static int getElapsedMillis(long logTime) {
37 | return (int) ((getLogTime() - logTime) * MILLIS_MULTIPLIER);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/NetWork.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.net.ConnectivityManager;
6 | import android.net.NetworkInfo;
7 |
8 | public class NetWork {
9 | public static boolean isNetworkAvailable(Context context) {
10 | try {
11 | ConnectivityManager mgr = (ConnectivityManager) context
12 | .getSystemService(Context.CONNECTIVITY_SERVICE);
13 | if (mgr == null) {
14 | return false;
15 | }
16 | @SuppressLint("MissingPermission") @SuppressWarnings("deprecation") NetworkInfo[] info = mgr.getAllNetworkInfo();
17 | if (info != null) {
18 | for (NetworkInfo anInfo : info) {
19 | if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
20 | return true;
21 | }
22 | }
23 | }
24 | } catch (Exception e) {
25 | //ignore
26 |
27 | }
28 | return false;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/Output.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 |
4 | import org.json.JSONException;
5 | import org.json.JSONObject;
6 |
7 | import fairy.easy.httpmodel.HttpModelHelper;
8 | import fairy.easy.httpmodel.model.HttpModel;
9 | import fairy.easy.httpmodel.model.ModelLoader;
10 | import fairy.easy.httpmodel.model.PostParam;
11 | import fairy.easy.httpmodel.model.RequestMethod;
12 | import fairy.easy.httpmodel.resource.base.BaseData;
13 |
14 | public class Output {
15 |
16 | public interface OutPutListener{
17 | void onSuccess(T t);
18 |
19 | void onFail(Exception e);
20 | }
21 |
22 | public static void getOutPutIp(final OutPutListener outPutListener) {
23 | ModelLoader modelLoader = HttpModelHelper.getInstance().getModelLoader();
24 | modelLoader.setHttpModel(new HttpModel(BaseData.BASE_URL + BaseData.OUTPUT_IP_URL, RequestMethod.GET, null));
25 | modelLoader.loadData(new ModelLoader.DataCallback() {
26 | @Override
27 | public void onDataReady( String data) {
28 | HttpLog.i("outputIp success:" + data);
29 | try {
30 | JSONObject jsonObject = new JSONObject(data);
31 | outPutListener.onSuccess(jsonObject.getString("ip"));
32 | } catch (JSONException e) {
33 | outPutListener.onFail(e);
34 | }
35 | }
36 |
37 | @Override
38 | public void onLoadFailed( Exception e) {
39 | HttpLog.e("outputIp fail:" + e.toString());
40 | outPutListener.onFail(e);
41 | }
42 | });
43 | }
44 |
45 |
46 | public static void getOutPutIpCountry(final OutPutListener outPutListener,String ip) {
47 | ModelLoader modelLoader = HttpModelHelper.getInstance().getModelLoader();
48 | JSONObject jsonObject = new JSONObject();
49 | try {
50 | jsonObject.put("ip", ip);
51 | jsonObject.put("ver", 1);
52 | } catch (JSONException e) {
53 | e.printStackTrace();
54 | }
55 | PostParam postParam = new PostParam(jsonObject);
56 | modelLoader.setHttpModel(new HttpModel(BaseData.BASE_URL + BaseData.OUTPUT_IP_COUNTRY_URL, RequestMethod.POST, postParam));
57 | modelLoader.loadData(new ModelLoader.DataCallback() {
58 | @Override
59 | public void onDataReady( String data) {
60 | HttpLog.i("outputIp info success:" + data);
61 | try {
62 | JSONObject jsonObject = new JSONObject(data);
63 | outPutListener.onSuccess(jsonObject.getString("country") + jsonObject.getString("province") + jsonObject.getString("isp"));
64 | } catch (JSONException e) {
65 | outPutListener.onFail(e);
66 | }
67 | }
68 |
69 | @Override
70 | public void onLoadFailed( Exception e) {
71 | HttpLog.e("outputIp info fail:" + e.toString());
72 | outPutListener.onFail(e);
73 | }
74 | });
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/PortScanTCP.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 | import java.net.InetSocketAddress;
6 | import java.net.Socket;
7 |
8 | import fairy.easy.httpmodel.resource.port.PortBean;
9 |
10 |
11 | public class PortScanTCP {
12 |
13 | private PortScanTCP() {
14 | }
15 |
16 |
17 | public static PortBean.PortNetBean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {
18 | PortBean.PortNetBean portNetBean = new PortBean.PortNetBean();
19 | long time = System.currentTimeMillis();
20 | Socket s = null;
21 | try {
22 | s = new Socket();
23 | s.connect(new InetSocketAddress(ia, portNo), timeoutMillis);
24 | portNetBean.setConnected(true);
25 | } catch (IOException e) {
26 | //ignore
27 | } finally {
28 | if (s != null) {
29 | try {
30 | s.close();
31 | } catch (IOException e) {
32 | e.printStackTrace();
33 | }
34 | }
35 | }
36 | portNetBean.setPort(portNo);
37 | portNetBean.setDelay(System.currentTimeMillis() - time);
38 | return portNetBean;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/PortScanUDP.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import java.net.DatagramPacket;
4 | import java.net.DatagramSocket;
5 | import java.net.InetAddress;
6 | import java.net.SocketTimeoutException;
7 |
8 | import fairy.easy.httpmodel.resource.port.PortBean;
9 |
10 |
11 | public class PortScanUDP {
12 |
13 | private PortScanUDP() {
14 | }
15 |
16 |
17 | public static PortBean.PortNetBean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {
18 | PortBean.PortNetBean portNetBean = new PortBean.PortNetBean();
19 | Long time = System.currentTimeMillis();
20 | try {
21 | byte[] bytes = new byte[128];
22 | DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
23 |
24 | DatagramSocket ds = new DatagramSocket();
25 | ds.setSoTimeout(timeoutMillis);
26 | ds.connect(ia, portNo);
27 | ds.send(dp);
28 | ds.isConnected();
29 | ds.receive(dp);
30 | ds.close();
31 | portNetBean.setConnected(true);
32 | } catch (SocketTimeoutException e) {
33 |
34 | } catch (Exception ignore) {
35 |
36 | }
37 | portNetBean.setPort(portNo);
38 | portNetBean.setDelay(System.currentTimeMillis() - time);
39 | return portNetBean;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/Preconditions.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import android.text.TextUtils;
4 |
5 | import java.util.Collection;
6 |
7 | /**
8 | * Contains common assertions.
9 | */
10 | public final class Preconditions {
11 |
12 | private Preconditions() {
13 | // Utility class.
14 | }
15 |
16 | public static void checkArgument(boolean expression, String message) {
17 | if (!expression) {
18 | throw new IllegalArgumentException(message);
19 | }
20 | }
21 |
22 | public static T checkNotNull(T arg) {
23 | return checkNotNull(arg, "Argument must not be null");
24 | }
25 |
26 |
27 | public static T checkNotNull(T arg, String message) {
28 | if (arg == null) {
29 | throw new NullPointerException(message);
30 | }
31 | return arg;
32 | }
33 |
34 | public static String checkNotEmpty(String string) {
35 | if (TextUtils.isEmpty(string)) {
36 | throw new IllegalArgumentException("Must not be null or empty");
37 | }
38 | return string;
39 | }
40 |
41 |
42 | public static , Y> T checkNotEmpty(T collection) {
43 | if (collection.isEmpty()) {
44 | throw new IllegalArgumentException("Must not be empty.");
45 | }
46 | return collection;
47 | }
48 |
49 | public static boolean checkNotEmptyBoolean(String string) {
50 | return !TextUtils.isEmpty(string);
51 | }
52 |
53 |
54 | public static String checkNotEmptyOfDefault(String string) {
55 | if (TextUtils.isEmpty(string)) {
56 | return "";
57 | }
58 | return string;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/httpmodel/src/main/java/fairy/easy/httpmodel/util/Task.java:
--------------------------------------------------------------------------------
1 | package fairy.easy.httpmodel.util;
2 |
3 | import android.text.TextUtils;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 | import java.util.concurrent.Callable;
10 |
11 | public class Task implements Callable {
12 | Integer i;
13 | String host;
14 | int size;
15 |
16 | public Task(Integer i, String host) {
17 | super();
18 | this.i = i;
19 | this.host = host;
20 | }
21 |
22 | @Override
23 | public Integer call() throws Exception {
24 | size = i;
25 | if (checkMtuFromPing(size, host)) {
26 | return size;
27 | } else {
28 | do {
29 | this.size = size - 28;
30 | HttpLog.e("当前size:"+size);
31 | if (checkMtuFromPing(size, host)) {
32 | return size;
33 | }
34 | } while (this.size > 100);
35 | }
36 | return size;
37 | }
38 |
39 | private boolean checkMtuFromPing(int size, String host) {
40 | String param = ping(createSimplePingCommand(size, host));
41 | if (TextUtils.isEmpty(param)) {
42 | return false;
43 | }
44 | if (param.toLowerCase().contains("icmp_seq")) {
45 | if (param.toLowerCase().contains("df")) {
46 | return false;
47 | }
48 | } else {
49 | return false;
50 | }
51 | return true;
52 | }
53 |
54 | private String createSimplePingCommand(int size, String host) {
55 | Object[] arrayOfObject = new Object[3];
56 | arrayOfObject[0] = size;
57 | arrayOfObject[1] = host;
58 | return String.format("/system/bin/ping -c 1 -w 1 -s %d %s", arrayOfObject);
59 | }
60 |
61 | private String ping(String command) {
62 | Process process = null;
63 | try {
64 | process = Runtime.getRuntime().exec(command);
65 | InputStream is = process.getInputStream();
66 | BufferedReader reader = new BufferedReader(new InputStreamReader(is));
67 | StringBuilder sb = new StringBuilder();
68 | String line;
69 | while (null != (line = reader.readLine())) {
70 | sb.append(line);
71 | sb.append("\n");
72 | }
73 | reader.close();
74 | is.close();
75 | return sb.toString();
76 | } catch (IOException e) {
77 | e.printStackTrace();
78 | } finally {
79 | if (null != process) {
80 | process.destroy();
81 | }
82 | }
83 | return null;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/param.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/param.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':httpmodel'
2 |
--------------------------------------------------------------------------------
/src/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guxiaonian/HttpInfo/06c591438074dcf4a8ab22fcce5b44b3e7a117fe/src/download.png
--------------------------------------------------------------------------------