aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/org/connectbot/data/HostStorage.java
blob: dc3e5d79d4747fde37a02b31178e736139f6ebc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * ConnectBot: simple, powerful, open-source SSH client for Android
 * Copyright 2015 Kenny Root, Jeffrey Sharkey
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.connectbot.data;

import java.util.List;
import java.util.Map;

import org.connectbot.bean.HostBean;
import org.connectbot.bean.PortForwardBean;

import com.trilead.ssh2.KnownHosts;

import android.support.annotation.VisibleForTesting;

/**
 * Interface that defines the operation used to interact with the storage layer.
 */
public interface HostStorage {
	/**
	 * Resets the database during testing.
	 */
	@VisibleForTesting
	void resetDatabase();

	/**
	 * Finds the host that is represented by the given selection.
	 * @param selection all fields to be considered
	 * @return the matching host
	 */
	HostBean findHost(Map<String, String> selection);

	/**
	 * Deletes the given {@code host} from the storage layer.
	 */
	void deleteHost(HostBean host);

	/**
	 * Saves the given {@code host} to the storage layer.
	 */
	HostBean saveHost(HostBean host);

	/**
	 * Returns a list of all the hosts as a list of {@link HostBean}.
	 * @param sortedByColor if hosts should be grouped by color.
	 */
	List<HostBean> getHosts(boolean sortedByColor);

	/**
	 * Updates the last connected time for {@code host}.
	 */
	void touchHost(HostBean host);

	/**
	 * Finds a {@link HostBean} based on the given {@code hostId}.
	 */
	HostBean findHostById(long hostId);

	/**
	 * Returns the list of known hosts.
	 *
	 * @see #saveKnownHost(String, int, String, byte[])
	 */
	KnownHosts getKnownHosts();

	/**
	 * Adds a known host to the database for later retrieval using {@link #getKnownHosts()}.
	 */
	void saveKnownHost(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey);

	/**
	 * Return all port forwards for the given {@code host}.
	 */
	List<PortForwardBean> getPortForwardsForHost(HostBean host);
}