root/src/vfs/sftpfs/vfs_subclass.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. sftpfs_cb_is_equal_connection
  2. sftpfs_cb_init_connection
  3. sftpfs_cb_open_connection
  4. sftpfs_cb_close_connection
  5. sftpfs_cb_dir_load
  6. sftpfs_init_subclass

   1 /* Virtual File System: SFTP file system.
   2    The VFS subclass functions
   3 
   4    Copyright (C) 2011-2019
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Ilia Maslakov <il.smind@gmail.com>, 2011
   9    Slava Zanko <slavazanko@gmail.com>, 2011, 2012, 2013
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 #include <config.h>
  28 #include <errno.h>
  29 #include <stdlib.h>
  30 #include <string.h>             /* memset() */
  31 
  32 #include "lib/global.h"
  33 #include "lib/widget.h"
  34 #include "lib/vfs/utilvfs.h"
  35 
  36 #include "internal.h"
  37 
  38 /*** global variables ****************************************************************************/
  39 
  40 /*** file scope macro definitions ****************************************************************/
  41 
  42 /*** file scope type declarations ****************************************************************/
  43 
  44 /*** file scope variables ************************************************************************/
  45 
  46 /*** file scope functions ************************************************************************/
  47 /* --------------------------------------------------------------------------------------------- */
  48 /**
  49  * Callback for checking if connection is equal to existing connection.
  50  *
  51  * @param vpath_element path element with connetion data
  52  * @param super         data with exists connection
  53  * @param vpath         unused
  54  * @param cookie        unused
  55  * @return TRUE if connections is equal, FALSE otherwise
  56  */
  57 
  58 static gboolean
  59 sftpfs_cb_is_equal_connection (const vfs_path_element_t * vpath_element, struct vfs_s_super *super,
     /* [previous][next][first][last][top][bottom][index][help]  */
  60                                const vfs_path_t * vpath, void *cookie)
  61 {
  62     int result;
  63     vfs_path_element_t *orig_connect_info;
  64 
  65     (void) vpath;
  66     (void) cookie;
  67 
  68     orig_connect_info = SFTP_SUPER (super)->original_connection_info;
  69 
  70     result = ((g_strcmp0 (vpath_element->host, orig_connect_info->host) == 0)
  71               && (g_strcmp0 (vpath_element->user, orig_connect_info->user) == 0)
  72               && (vpath_element->port == orig_connect_info->port));
  73 
  74     return result;
  75 }
  76 
  77 /* --------------------------------------------------------------------------------------------- */
  78 
  79 static struct vfs_s_super *
  80 sftpfs_cb_init_connection (struct vfs_class *me)
     /* [previous][next][first][last][top][bottom][index][help]  */
  81 {
  82     sftpfs_super_t *arch;
  83 
  84     arch = g_new0 (sftpfs_super_t, 1);
  85     arch->base.me = me;
  86     arch->base.name = g_strdup (PATH_SEP_STR);
  87     arch->auth_type = NONE;
  88     arch->config_auth_type = NONE;
  89     arch->socket_handle = LIBSSH2_INVALID_SOCKET;
  90 
  91     return VFS_SUPER (arch);
  92 }
  93 
  94 /* --------------------------------------------------------------------------------------------- */
  95 /**
  96  * Callback for opening new connection.
  97  *
  98  * @param super         connection data
  99  * @param vpath         unused
 100  * @param vpath_element path element with connetion data
 101  * @return 0 if success, -1 otherwise
 102  */
 103 
 104 static int
 105 sftpfs_cb_open_connection (struct vfs_s_super *super,
     /* [previous][next][first][last][top][bottom][index][help]  */
 106                            const vfs_path_t * vpath, const vfs_path_element_t * vpath_element)
 107 {
 108     GError *mcerror = NULL;
 109     sftpfs_super_t *sftpfs_super = SFTP_SUPER (super);
 110     int ret_value;
 111 
 112     (void) vpath;
 113 
 114     if (vpath_element->host == NULL || *vpath_element->host == '\0')
 115     {
 116         vfs_print_message ("%s", _("sftp: Invalid host name."));
 117         vpath_element->class->verrno = EPERM;
 118         return -1;
 119     }
 120 
 121     sftpfs_super->original_connection_info = vfs_path_element_clone (vpath_element);
 122     super->path_element = vfs_path_element_clone (vpath_element);
 123 
 124     sftpfs_fill_connection_data_from_config (super, &mcerror);
 125     if (mc_error_message (&mcerror, &ret_value))
 126     {
 127         vpath_element->class->verrno = ret_value;
 128         return -1;
 129     }
 130 
 131     super->root =
 132         vfs_s_new_inode (vpath_element->class, super,
 133                          vfs_s_default_stat (vpath_element->class, S_IFDIR | 0755));
 134 
 135     ret_value = sftpfs_open_connection (super, &mcerror);
 136     mc_error_message (&mcerror, NULL);
 137     return ret_value;
 138 }
 139 
 140 /* --------------------------------------------------------------------------------------------- */
 141 /**
 142  * Callback for closing connection.
 143  *
 144  * @param me    unused
 145  * @param super connection data
 146  */
 147 
 148 static void
 149 sftpfs_cb_close_connection (struct vfs_class *me, struct vfs_s_super *super)
     /* [previous][next][first][last][top][bottom][index][help]  */
 150 {
 151     GError *mcerror = NULL;
 152 
 153     (void) me;
 154     sftpfs_close_connection (super, "Normal Shutdown", &mcerror);
 155 
 156     vfs_path_element_free (SFTP_SUPER (super)->original_connection_info);
 157 
 158     mc_error_message (&mcerror, NULL);
 159 }
 160 
 161 /* --------------------------------------------------------------------------------------------- */
 162 /**
 163  * Callback for getting directory content.
 164  *
 165  * @param me          unused
 166  * @param dir         unused
 167  * @param remote_path unused
 168  * @return always 0
 169  */
 170 
 171 static int
 172 sftpfs_cb_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
     /* [previous][next][first][last][top][bottom][index][help]  */
 173 {
 174     (void) me;
 175     (void) dir;
 176     (void) remote_path;
 177 
 178     return 0;
 179 }
 180 
 181 /* --------------------------------------------------------------------------------------------- */
 182 /*** public functions ****************************************************************************/
 183 /* --------------------------------------------------------------------------------------------- */
 184 /**
 185  * Initialization of VFS subclass structure.
 186  *
 187  * @return VFS subclass structure.
 188  */
 189 
 190 void
 191 sftpfs_init_subclass (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 192 {
 193     sftpfs_subclass.archive_same = sftpfs_cb_is_equal_connection;
 194     sftpfs_subclass.new_archive = sftpfs_cb_init_connection;
 195     sftpfs_subclass.open_archive = sftpfs_cb_open_connection;
 196     sftpfs_subclass.free_archive = sftpfs_cb_close_connection;
 197     sftpfs_subclass.fh_new = sftpfs_fh_new;
 198     sftpfs_subclass.dir_load = sftpfs_cb_dir_load;
 199 }
 200 
 201 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */