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 Object
`GhidraProtocolConnector` provides 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 String`
  `folderItemName`
  `protected String`
  `folderPath`
  `protected final String`
  `itemPath`
  `protected RepositoryAdapter`
  `repositoryAdapter`
  `protected String`
  `repositoryName`
  `protected RepositoryServerAdapter`
  `repositoryServerAdapter`
  `protected GhidraURLConnection.StatusCode`
  `statusCode`
  `protected final URL`
  `url`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `GhidraProtocolConnector(URL url)`
  Abstract `GhidraProtocolConnector` constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `checkHostInfo()`
  Presence of a host specification within URL will be verified
  `protected void`
  `checkProtocol()`
  Perform URL verification checks to ensure that it satisfies this connector implementation requirements
  `protected void`
  `checkUserInfo()`
  If connector supports user information within URL it will be verified
  `abstract GhidraURLConnection.StatusCode`
  `connect(boolean readOnly)`
  Connect to the resource specified by the associated URL.
  `protected void`
  `connect(RepositoryAdapter repository)`
  Utilized a cached connection via the specified repository adapter.
  `String`
  `getFolderItemName()`
  Gets the repository folder item name associated with the URL.
  `String`
  `getFolderPath()`
  Gets the repository folder path associated with the URL.
  `RepositoryAdapter`
  `getRepositoryAdapter()`
  Get the RepositoryAdapter associated with a URL which specifies a repository.
  `String`
  `getRepositoryName()`
  Gets the repository name associated with the URL.
  `protected abstract URL`
  `getRepositoryRootGhidraURL()`
  Get the URL associated with the repository/project root folder.
  `RepositoryServerAdapter`
  `getRepositoryServerAdapter()`
  Get the RepositoryServerAdapter associated with a URL which specifies a repository or repository server.
  `GhidraURLConnection.StatusCode`
  `getStatusCode()`
  Gets the status code from a Ghidra URL connect attempt.
  `protected final String`
  `initFolderItemPath(String contentPath)`
  Initialize `folderPath` and `folderItemName` from specified `contentPath`.
  `abstract boolean`
  `isReadOnly()`
  Determines the read-only nature of a connected resource
  `protected String`
  `parseItemPath()`
  Parse item path name from URL and establish initial values for folderPath and folderItemName.
  `protected void`
  `resolveItemPath()`
  Fully resolve folder/item reference once connected to the associated repository due to possible ambiguity

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### url

    protected final URL url

  - ### repositoryName

    protected String repositoryName

  - ### itemPath

    protected final String itemPath

  - ### folderPath

    protected String folderPath

  - ### folderItemName

    protected String folderItemName

  - ### statusCode

    protected GhidraURLConnection.StatusCode statusCode

  - ### repositoryAdapter

    protected RepositoryAdapter repositoryAdapter

  - ### repositoryServerAdapter

    protected RepositoryServerAdapter repositoryServerAdapter

- ## Constructor Details

  - ### GhidraProtocolConnector

    protected GhidraProtocolConnector(URL url) throws MalformedURLException
    Abstract `GhidraProtocolConnector` constructor.
    Parameters:
      `url` - a repository resource URL appropriate for the specific protocol implementation
    Throws:
      `MalformedURLException` - if URL is invalid

- ## Method Details

  - ### getRepositoryRootGhidraURL

    protected abstract 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 MalformedURLException
    Perform URL verification checks to ensure that it satisfies this connector implementation requirements
    Throws:
      `MalformedURLException` - if URL is invalid

  - ### checkUserInfo

    protected void checkUserInfo() throws MalformedURLException
    If connector supports user information within URL it will be verified
    Throws:
      `MalformedURLException` - if URL contains user information and it is either invalid or unsupported

  - ### checkHostInfo

    protected void checkHostInfo() throws MalformedURLException
    Presence of a host specification within URL will be verified
    Throws:
      `MalformedURLException` - if URL is missing proper host specification

  - ### initFolderItemPath

    protected final String initFolderItemPath(String contentPath) throws MalformedURLException
    Initialize `folderPath` and `folderItemName` from specified `contentPath`.
    Parameters:
      `contentPath` - absolute content path (null not permitted)
    Returns:
      full content path
    Throws:
      `MalformedURLException` - if non-null invalid `contentPath` specified

  - ### parseItemPath

    protected String parseItemPath() throws MalformedURLException
    Parse 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:
      `MalformedURLException` - if URL is invalid

  - ### getStatusCode

    public GhidraURLConnection.StatusCode getStatusCode()
    Gets the status code from a Ghidra URL connect attempt.
    Returns:
      the Ghidra status code or null if not yet connected
    See Also:
      - `connect(boolean)`

  - ### getRepositoryName

    public String getRepositoryName()
    Gets the repository name associated with the URL. If a local URL is used this will correspond to the project name.
    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 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 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 IOException
    Fully resolve folder/item reference once connected to the associated repository due to possible ambiguity
    Throws:
      `IOException` - if an IO error occurs

  - ### connect

    protected void connect(RepositoryAdapter repository) throws 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 status 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:
      `IOException` - if an IO error occurs

  - ### connect

    public abstract GhidraURLConnection.StatusCode connect(boolean readOnly) throws IOException
    Connect 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 status code
    Throws:
      `IOException` - if a connection error occurs

  - ### isReadOnly

    public abstract boolean isReadOnly() throws NotConnectedException
    Determines 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