void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message, GError ** error) { sftpfs_super_data_t *super_data; (void) error; super_data = (sftpfs_super_data_t *) super->data; if (super_data == NULL) return; vfs_path_element_free (super_data->original_connection_info); super_data->original_connection_info = NULL; if (super_data->agent != NULL) { libssh2_agent_disconnect (super_data->agent); libssh2_agent_free (super_data->agent); super_data->agent = NULL; } if (super_data->sftp_session != NULL) { libssh2_sftp_shutdown (super_data->sftp_session); super_data->sftp_session = NULL; } if (super_data->session != NULL) { libssh2_session_disconnect (super_data->session, shutdown_message); super_data->session = NULL; } super_data->fingerprint = NULL; if (super_data->socket_handle != -1) { close (super_data->socket_handle); super_data->socket_handle = -1; } }
vfs_path_element_t * vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) { vfs_path_element_t *path_element; char *pcopy; size_t pcopy_len; const char *pend; char *dir, *colon, *at, *rest; path_element = g_new0 (vfs_path_element_t, 1); path_element->port = default_port; pcopy_len = strlen (path); pcopy = g_strndup (path, pcopy_len); pend = pcopy + pcopy_len; dir = pcopy; if ((flags & URL_NOSLASH) == 0) { /* locate path component */ while (*dir != PATH_SEP && *dir != '\0') dir++; if (*dir == '\0') path_element->path = g_strdup (PATH_SEP_STR); else { path_element->path = g_strndup (dir, pcopy_len - (size_t) (dir - pcopy)); *dir = '\0'; } } /* search for any possible user */ at = strrchr (pcopy, '@'); /* We have a username */ if (at == NULL) rest = pcopy; else { char *inner_colon; *at = '\0'; inner_colon = strchr (pcopy, ':'); if (inner_colon != NULL) { *inner_colon = '\0'; inner_colon++; path_element->password = g_strdup (inner_colon); } if (*pcopy != '\0') path_element->user = g_strdup (pcopy); if (pend == at + 1) rest = at; else rest = at + 1; } if ((flags & URL_USE_ANONYMOUS) == 0) path_element->user = vfs_get_local_username (); /* Check if the host comes with a port spec, if so, chop it */ if (*rest != '[') colon = strchr (rest, ':'); else { colon = strchr (++rest, ']'); if (colon != NULL) { colon[0] = '\0'; colon[1] = '\0'; colon++; } else { vfs_path_element_free (path_element); return NULL; } } if (colon != NULL) { *colon = '\0'; /* cppcheck-suppress invalidscanf */ if (sscanf (colon + 1, "%d", &path_element->port) == 1) { if (path_element->port <= 0 || path_element->port >= 65536) path_element->port = default_port; } else while (*(++colon) != '\0') { switch (*colon) { case 'C': path_element->port = 1; break; case 'r': path_element->port = 2; break; } } } path_element->host = g_strdup (rest); #ifdef HAVE_CHARSET path_element->dir.converter = INVALID_CONV; #endif return path_element; }