rofi 1.7.5
Collaboration diagram for SSH:

Variables

Mode ssh_mode
 
Mode ssh_mode
 
#define G_LOG_DOMAIN   "Modes.Ssh"
 
#define SSH_CACHE_FILE   "rofi-2.sshcache"
 
#define SSH_TOKEN_DELIM   "= \t\r\n"
 
typedef struct _SshEntry SshEntry
 
static int execshssh (const SshEntry *entry)
 
static void exec_ssh (const SshEntry *entry)
 
static void delete_ssh (const char *host)
 
static SshEntryread_known_hosts_file (const char *path, SshEntry *retv, unsigned int *length)
 
static SshEntryread_hosts_file (SshEntry *retv, unsigned int *length)
 
static void add_known_hosts_file (SSHModePrivateData *pd, const char *token)
 
static void parse_ssh_config_file (SSHModePrivateData *pd, const char *filename, SshEntry **retv, unsigned int *length, unsigned int num_favorites)
 
static SshEntryget_ssh (SSHModePrivateData *pd, unsigned int *length)
 
static int ssh_mode_init (Mode *sw)
 
static unsigned int ssh_mode_get_num_entries (const Mode *sw)
 
static void ssh_mode_destroy (Mode *sw)
 
static ModeMode ssh_mode_result (Mode *sw, int mretv, char **input, unsigned int selected_line)
 
static char * _get_display_value (const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
 
static int ssh_token_match (const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
 

Detailed Description

SSH Mode, returns a list of known SSH hosts the user can log into. It does this by parsing the SSH config file and optional the known host and host list It also keeps history of the last chosen hosts.

This mode uses the following options from the config object:

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "Modes.Ssh"

Log domain for the ssh mode.

Definition at line 36 of file ssh.c.

◆ SSH_CACHE_FILE

#define SSH_CACHE_FILE   "rofi-2.sshcache"

Name of the history file where previously chosen hosts are stored.

Definition at line 82 of file ssh.c.

Referenced by delete_ssh(), exec_ssh(), and get_ssh().

◆ SSH_TOKEN_DELIM

#define SSH_TOKEN_DELIM   "= \t\r\n"

Used in get_ssh() when splitting lines from the user's SSH config file into tokens.

Definition at line 88 of file ssh.c.

Referenced by parse_ssh_config_file().

Typedef Documentation

◆ SshEntry

typedef struct _SshEntry SshEntry

Holding an ssh entry.

Function Documentation

◆ _get_display_value()

static char * _get_display_value ( const Mode * sw,
unsigned int selected_line,
G_GNUC_UNUSED int * state,
G_GNUC_UNUSED GList ** attr_list,
int get_entry )
static
Parameters
swObject handle to the SSH Mode object
selected_lineThe line to view
stateThe state of the entry [out]
attr_listList of extra rendering attributes to set [out]
get_entry

Gets the string as it should be displayed and the display state. If get_entry is FALSE only the state is set.

Returns
the string as it should be displayed and the display state.

Definition at line 614 of file ssh.c.

References _SshEntry::hostname, SSHModePrivateData::hosts_list, and mode_get_private_data().

Here is the call graph for this function:

◆ add_known_hosts_file()

static void add_known_hosts_file ( SSHModePrivateData * pd,
const char * token )
static

Definition at line 331 of file ssh.c.

References SSHModePrivateData::user_known_hosts.

Referenced by parse_ssh_config_file().

Here is the caller graph for this function:

◆ delete_ssh()

static void delete_ssh ( const char * host)
static
Parameters
hostThe host to remove from history

Remove host from history.

Definition at line 154 of file ssh.c.

References cache_dir, history_remove(), and SSH_CACHE_FILE.

Referenced by ssh_mode_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_ssh()

static void exec_ssh ( const SshEntry * entry)
static
Parameters
entryThe host to connect too

SSH into the selected host, if successful update history.

Definition at line 126 of file ssh.c.

References cache_dir, execshssh(), history_set(), _SshEntry::hostname, _SshEntry::port, and SSH_CACHE_FILE.

Referenced by ssh_mode_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execshssh()

static int execshssh ( const SshEntry * entry)
static
Parameters
entryThe host to connect too

SSH into the selected host.

Returns
FALSE On failure, TRUE on success

Definition at line 97 of file ssh.c.

References config, helper_execute(), helper_parse_setup(), _SshEntry::hostname, RofiHelperExecuteContext::name, _SshEntry::port, and Settings::ssh_command.

Referenced by exec_ssh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ssh()

static SshEntry * get_ssh ( SSHModePrivateData * pd,
unsigned int * length )
static
Parameters
pdThe plugin data handle
lengthThe number of found ssh hosts [out]

Gets the list available SSH hosts.

Returns
an array of strings containing all the hosts.

Definition at line 456 of file ssh.c.

References cache_dir, config, history_get_list(), _SshEntry::hostname, Settings::parse_hosts, Settings::parse_known_hosts, parse_ssh_config_file(), _SshEntry::port, read_hosts_file(), read_known_hosts_file(), rofi_expand_path(), SSH_CACHE_FILE, and SSHModePrivateData::user_known_hosts.

Referenced by ssh_mode_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_ssh_config_file()

static void parse_ssh_config_file ( SSHModePrivateData * pd,
const char * filename,
SshEntry ** retv,
unsigned int * length,
unsigned int num_favorites )
static

Definition at line 342 of file ssh.c.

References add_known_hosts_file(), parse_ssh_config_file(), rofi_expand_path(), and SSH_TOKEN_DELIM.

Referenced by get_ssh(), and parse_ssh_config_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_hosts_file()

static SshEntry * read_hosts_file ( SshEntry * retv,
unsigned int * length )
static
Parameters
retvThe list of hosts to update.
lengthThe length of the list retv [in][out]

Read /etc/hosts and appends them to the list retv

Returns
an updated list with the added hosts.

Definition at line 266 of file ssh.c.

References _SshEntry::hostname, and _SshEntry::port.

Referenced by get_ssh().

Here is the caller graph for this function:

◆ read_known_hosts_file()

static SshEntry * read_known_hosts_file ( const char * path,
SshEntry * retv,
unsigned int * length )
static
Parameters
pathPath of the known host file.
retvlist of hosts
lengthpointer to length of list [in][out]

Read 'known_hosts' file when entries are not hashed.

Returns
updated list of hosts.

Definition at line 172 of file ssh.c.

References _SshEntry::hostname, and _SshEntry::port.

Referenced by get_ssh().

Here is the caller graph for this function:

◆ ssh_mode_destroy()

static void ssh_mode_destroy ( Mode * sw)
static
Parameters
swObject handle to the SSH Mode object

Cleanup the SSH Mode. Free all allocated memory and NULL the private data pointer.

Definition at line 556 of file ssh.c.

References _SshEntry::hostname, SSHModePrivateData::hosts_list, SSHModePrivateData::hosts_list_length, mode_get_private_data(), mode_set_private_data(), and SSHModePrivateData::user_known_hosts.

Referenced by ssh_mode_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ssh_mode_get_num_entries()

static unsigned int ssh_mode_get_num_entries ( const Mode * sw)
static
Parameters
swObject handle to the SSH Mode object

Get the number of SSH entries.

Returns
the number of ssh entries.

Definition at line 545 of file ssh.c.

References SSHModePrivateData::hosts_list_length, and mode_get_private_data().

Here is the call graph for this function:

◆ ssh_mode_init()

static int ssh_mode_init ( Mode * sw)
static
Parameters
swObject handle to the SSH Mode object

Initializes the SSH Mode private data object and loads the relevant ssh information.

Definition at line 529 of file ssh.c.

References get_ssh(), SSHModePrivateData::hosts_list, SSHModePrivateData::hosts_list_length, mode_get_private_data(), and mode_set_private_data().

Referenced by ssh_mode_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ssh_mode_result()

static ModeMode ssh_mode_result ( Mode * sw,
int mretv,
char ** input,
unsigned int selected_line )
static
Parameters
swObject handle to the SSH Mode object
mretvThe menu return value.
inputPointer to the user input string.
selected_linethe line selected by the user.

Acts on the user interaction.

Returns
the next ModeMode.

Definition at line 579 of file ssh.c.

References delete_ssh(), exec_ssh(), _SshEntry::hostname, SSHModePrivateData::hosts_list, MENU_CUSTOM_COMMAND, MENU_CUSTOM_INPUT, MENU_ENTRY_DELETE, MENU_LOWER_MASK, MENU_OK, MODE_EXIT, mode_get_private_data(), RELOAD_DIALOG, ssh_mode_destroy(), and ssh_mode_init().

Here is the call graph for this function:

◆ ssh_token_match()

static int ssh_token_match ( const Mode * sw,
rofi_int_matcher ** tokens,
unsigned int index )
static
Parameters
swObject handle to the SSH Mode object
tokensThe set of tokens to match against
indexThe index of the entry to match

Match entry against the set of tokens.

Returns
TRUE if matches

Definition at line 631 of file ssh.c.

References helper_token_match(), _SshEntry::hostname, SSHModePrivateData::hosts_list, and mode_get_private_data().

Here is the call graph for this function:

Variable Documentation

◆ ssh_mode [1/2]

Mode ssh_mode
extern

Mode object representing the ssh mode.

Definition at line 637 of file ssh.c.

Referenced by rofi_collect_modes().

◆ ssh_mode [2/2]

Mode ssh_mode
Initial value:
= {.name = "ssh",
.cfg_name_key = "display-ssh",
._init = ssh_mode_init,
._get_num_entries = ssh_mode_get_num_entries,
._result = ssh_mode_result,
._destroy = ssh_mode_destroy,
._token_match = ssh_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL}
static int ssh_mode_init(Mode *sw)
Definition ssh.c:529
static int ssh_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
Definition ssh.c:631
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
Definition ssh.c:614
static ModeMode ssh_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
Definition ssh.c:579
static void ssh_mode_destroy(Mode *sw)
Definition ssh.c:556
static unsigned int ssh_mode_get_num_entries(const Mode *sw)
Definition ssh.c:545

Mode object representing the ssh mode.

Definition at line 637 of file ssh.c.

Referenced by rofi_collect_modes().