Package ghidra.framework.protocol.ghidra
Class GhidraProtocolConnector
- java.lang.Object
-
- ghidra.framework.protocol.ghidra.GhidraProtocolConnector
-
- Direct Known Subclasses:
DefaultGhidraProtocolConnector,DefaultLocalGhidraProtocolConnector
public abstract class GhidraProtocolConnector extends java.lang.ObjectGhidraProtocolConnectorprovides an abtract implementation to access Ghidra repositories using various underlying communication protocols. The common requirement for all implementations is the ability to derive a repository URL from any folder or file URL.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringfolderItemNameprotected java.lang.StringfolderPathprotected java.lang.StringitemPathprotected RepositoryAdapterrepositoryAdapterprotected java.lang.StringrepositoryNameprotected RepositoryServerAdapterrepositoryServerAdapterprotected intresponseCodeprotected java.net.URLurl
-
Constructor Summary
Constructors Modifier Constructor Description protectedGhidraProtocolConnector(java.net.URL url)AbstractGhidraProtocolConnectorconstructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckHostInfo()Presence of a host specification within URL will be verifiedprotected voidcheckProtocol()Perform URL verification checks to ensure that it satisfies this connector implementation requirementsprotected voidcheckUserInfo()If connector supports user information within URL it will be verifiedabstract intconnect(boolean readOnly)Connect to the resource specified by the associated URL.protected voidconnect(RepositoryAdapter repository)Utilized a cached connection via the specified repository adapter.java.lang.StringgetFolderItemName()Gets the repository folder item name associated with the URL.java.lang.StringgetFolderPath()Gets the repository folder path associated with the URL.RepositoryAdaptergetRepositoryAdapter()Get the RepositoryAdapter associated with a URL which specifies a repository.java.lang.StringgetRepositoryName()Gets the repository name associated with the URL.protected abstract java.net.URLgetRepositoryRootGhidraURL()Get the URL associated with the repository/project root folder.RepositoryServerAdaptergetRepositoryServerAdapter()Get the RepositoryServerAdapter associated with a URL which specifies a repository or repository server.intgetResponseCode()Gets the status code from a Ghidra URL connect response.abstract booleanisReadOnly()Determines the read-only nature of a connected resourceprotected java.lang.StringparseItemPath()Parse item path name from URL and establish initial values for folderPath and folderItemName.protected java.lang.StringparseRepositoryName()Parse repository name from URLprotected voidresolveItemPath()Fully resolve folder/item reference once connected to the associated repository due to possible ambiguity
-
-
-
Field Detail
-
url
protected final java.net.URL url
-
repositoryName
protected final java.lang.String repositoryName
-
itemPath
protected final java.lang.String itemPath
-
folderPath
protected java.lang.String folderPath
-
folderItemName
protected java.lang.String folderItemName
-
responseCode
protected int responseCode
-
repositoryAdapter
protected RepositoryAdapter repositoryAdapter
-
repositoryServerAdapter
protected RepositoryServerAdapter repositoryServerAdapter
-
-
Constructor Detail
-
GhidraProtocolConnector
protected GhidraProtocolConnector(java.net.URL url) throws java.net.MalformedURLExceptionAbstractGhidraProtocolConnectorconstructor.- Parameters:
url- a repository resource URL appropriate for the specific protocol implementation- Throws:
java.net.MalformedURLException- if URL is invalid
-
-
Method Detail
-
getRepositoryRootGhidraURL
protected abstract java.net.URL getRepositoryRootGhidraURL()
Get the URL associated with the repository/project root folder. This will be used as a key to its corresponding transient project data.- Returns:
- root folder URL
-
checkProtocol
protected void checkProtocol() throws java.net.MalformedURLExceptionPerform URL verification checks to ensure that it satisfies this connector implementation requirements- Throws:
java.net.MalformedURLException- if URL is invalid
-
checkUserInfo
protected void checkUserInfo() throws java.net.MalformedURLExceptionIf connector supports user information within URL it will be verified- Throws:
java.net.MalformedURLException- if URL contains user information and it is either invalid or unsupported
-
checkHostInfo
protected void checkHostInfo() throws java.net.MalformedURLExceptionPresence of a host specification within URL will be verified- Throws:
java.net.MalformedURLException- if URL is missing proper host specification
-
parseRepositoryName
protected java.lang.String parseRepositoryName() throws java.net.MalformedURLExceptionParse repository name from URL- Returns:
- repository name or null if not specified
- Throws:
java.net.MalformedURLException- if URL is invalid
-
parseItemPath
protected java.lang.String parseItemPath() throws java.net.MalformedURLExceptionParse item path name from URL and establish initial values for folderPath and folderItemName.- Returns:
- original item path from URL or null if not specified
- Throws:
java.net.MalformedURLException- if URL is invalid
-
getResponseCode
public int getResponseCode()
Gets the status code from a Ghidra URL connect response.- Returns:
- the Ghidra Status-Code, or -1 if not yet connected
- See Also:
connect(boolean)
-
getRepositoryName
public java.lang.String getRepositoryName()
Gets the repository name associated with the URL.- Returns:
- the repository name or null if URL does not identify a specific repository
-
getRepositoryAdapter
public RepositoryAdapter getRepositoryAdapter()
Get the RepositoryAdapter associated with a URL which specifies a repository.- Returns:
- repository adapter or null if a project locator is supplied instead
-
getRepositoryServerAdapter
public RepositoryServerAdapter getRepositoryServerAdapter()
Get the RepositoryServerAdapter associated with a URL which specifies a repository or repository server.- Returns:
- repository server adapter or null if a project locator is supplied instead
-
getFolderPath
public java.lang.String getFolderPath()
Gets the repository folder path associated with the URL. If an ambiguous path has been specified, the folder path may change after a connection is established (e.g., folder item name will be appended to folder path and item name will become null if item turns out to be a folder).- Returns:
- repository folder path or null
-
getFolderItemName
public java.lang.String getFolderItemName()
Gets the repository folder item name associated with the URL. If an ambiguous path has been specified, the folder item name may become null after a connection is established (e.g., folder item name will be appended to folder path and item name will become null if item turns out to be a folder).- Returns:
- folder item name or null
-
resolveItemPath
protected void resolveItemPath() throws java.io.IOExceptionFully resolve folder/item reference once connected to the associated repository due to possible ambiguity- Throws:
java.io.IOException
-
connect
protected void connect(RepositoryAdapter repository) throws java.io.IOException
Utilized a cached connection via the specified repository adapter. This method may only be invoked if not yet connected and the associated URL corresponds to a repository (getRepositoryName() != null). The connection response code should be established based upon the availability of the URL referenced repository resource (i.e., folder or file).- Parameters:
repository- existing connected repository adapter- Throws:
java.io.IOException
-
connect
public abstract int connect(boolean readOnly) throws java.io.IOExceptionConnect to the resource specified by the associated URL. This method should only be invoked once, a second attempt may result in an IOException.- Parameters:
readOnly- if resource should be requested for write access.- Returns:
- connection response code @see
GhidraURLConnection - Throws:
java.io.IOException- if a connection error occurs
-
isReadOnly
public abstract boolean isReadOnly() throws NotConnectedExceptionDetermines the read-only nature of a connected resource- Returns:
- true if read-only, false if write access allowed
- Throws:
NotConnectedException- if connect has not yet been performed
-
-