Class GhidraURLConnection


  • public class GhidraURLConnection
    extends java.net.URLConnection
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int GHIDRA_NOT_FOUND
      Ghidra Status-Code 404: Not Found.
      static int GHIDRA_OK
      Ghidra Status-Code 200: OK.
      static int GHIDRA_UNAUTHORIZED
      Ghidra Status-Code 401: Unauthorized.
      static java.lang.String GHIDRA_WRAPPED_CONTENT
      Ghidra content type - domain folder/file wrapped within GhidraURLWrappedContent object.
      static java.lang.String REPOSITORY_SERVER_CONTENT
      Ghidra content type - repository server in the form of a RepositoryAdapter
      • Fields inherited from class java.net.URLConnection

        allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
    • Constructor Summary

      Constructors 
      Constructor Description
      GhidraURLConnection​(java.net.URL ghidraUrl)
      Construct a Ghidra URL connection which uses the default handler without any extension protocol.
      GhidraURLConnection​(java.net.URL url, GhidraProtocolHandler protocolHandler)
      Construct a Ghidra URL connection which requires an Ghidra protocol extension
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void connect()  
      java.lang.Object getContent()
      Get content associated with the URL
      java.lang.String getContentType()  
      java.lang.String getFolderItemName()
      Gets the repository folder item name associated with this connection.
      java.lang.String getFolderPath()
      Gets the repository folder path associated with this connection.
      java.io.InputStream getInputStream()  
      java.io.OutputStream getOutputStream()  
      ProjectData getProjectData()
      If URL connects and corresponds to a valid repository, this method may be used to obtain the associated ProjectData object.
      java.lang.String getRepositoryName()
      Gets the repository name associated with this GhidraURLConnection.
      int getResponseCode()
      Gets the status code from a Ghidra URL response.
      boolean isReadOnly()
      Connection was opened as read-only
      void setReadOnly​(boolean state)
      Set the read-only state of the content.
      • Methods inherited from class java.net.URLConnection

        addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContentEncoding, getContentLength, getContentLengthLong, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getLastModified, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • GHIDRA_OK

        public static final int GHIDRA_OK
        Ghidra Status-Code 200: OK.
        See Also:
        Constant Field Values
      • GHIDRA_UNAUTHORIZED

        public static final int GHIDRA_UNAUTHORIZED
        Ghidra Status-Code 401: Unauthorized. This response code includes a variety of connection errors which are reported/logged by the Ghidra Server support code.
        See Also:
        Constant Field Values
      • GHIDRA_NOT_FOUND

        public static final int GHIDRA_NOT_FOUND
        Ghidra Status-Code 404: Not Found.
        See Also:
        Constant Field Values
      • GHIDRA_WRAPPED_CONTENT

        public static final java.lang.String GHIDRA_WRAPPED_CONTENT
        Ghidra content type - domain folder/file wrapped within GhidraURLWrappedContent object.
        See Also:
        GhidraURLWrappedContent, Constant Field Values
      • REPOSITORY_SERVER_CONTENT

        public static final java.lang.String REPOSITORY_SERVER_CONTENT
        Ghidra content type - repository server in the form of a RepositoryAdapter
        See Also:
        RepositoryAdapter, Constant Field Values
    • Constructor Detail

      • GhidraURLConnection

        public GhidraURLConnection​(java.net.URL ghidraUrl)
                            throws java.net.MalformedURLException
        Construct a Ghidra URL connection which uses the default handler without any extension protocol.
        Parameters:
        ghidraUrl - ghidra protocol URL (e.g., ghidra://server/repo)
        Throws:
        java.net.MalformedURLException - if URL is invalid
      • GhidraURLConnection

        public GhidraURLConnection​(java.net.URL url,
                                   GhidraProtocolHandler protocolHandler)
                            throws java.net.MalformedURLException
        Construct a Ghidra URL connection which requires an Ghidra protocol extension
        Parameters:
        url - extension URL without the ghidra protocol prefix (e.g., http://server/repo)
        protocolHandler - Ghidra protocol extension handler
        Throws:
        java.net.MalformedURLException - if URL is invalid
    • Method Detail

      • isReadOnly

        public boolean isReadOnly()
        Connection was opened as read-only
        Returns:
        true if read-only connection
      • setReadOnly

        public void setReadOnly​(boolean state)
        Set the read-only state of the content. Extreme care must be taken when setting the state to false for local projects without the use of a ProjectLock. This setting is currently ignored for server repositories which are always read-only in Headed mode and read-write in Headless mode.
        Parameters:
        state - read-only if true, otherwise read-write
      • getRepositoryName

        public java.lang.String getRepositoryName()
        Gets the repository name associated with this GhidraURLConnection.
        Returns:
        the repository name or null if URL does not identify a specific repository
      • getFolderPath

        public java.lang.String getFolderPath()
        Gets the repository folder path associated with this connection. 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 this connection. 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
      • getResponseCode

        public int getResponseCode()
                            throws java.io.IOException
        Gets the status code from a Ghidra URL response.
        Returns:
        the Ghidra Status-Code, or -1
        Throws:
        java.io.IOException - if an error occurred connecting to the server.
      • getContentType

        public java.lang.String getContentType()
        Overrides:
        getContentType in class java.net.URLConnection
      • getContent

        public java.lang.Object getContent()
                                    throws java.io.IOException
        Get content associated with the URL
        Overrides:
        getContent in class java.net.URLConnection
        Returns:
        URL content generally in the form of GhidraURLWrappedContent, although other special cases may result in different content (Example: a server-only URL could result in content class of RepositoryServerAdapter).
        Throws:
        java.io.IOException
      • getProjectData

        public ProjectData getProjectData()
                                   throws java.io.IOException
        If URL connects and corresponds to a valid repository, this method may be used to obtain the associated ProjectData object. The caller is responsible for closing the returned project data when no longer in-use, failure to do so may prevent release of repository handle to server. Only a single call to this method is permitted.
        Returns:
        transient project data or null if unavailable
        Throws:
        java.io.IOException
      • connect

        public void connect()
                     throws java.io.IOException
        Specified by:
        connect in class java.net.URLConnection
        Throws:
        java.io.IOException
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Overrides:
        getInputStream in class java.net.URLConnection
        Throws:
        java.io.IOException
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        Overrides:
        getOutputStream in class java.net.URLConnection
        Throws:
        java.io.IOException