sftp.c (3084B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "config.h" 21 22#include "common-ssh/sftp.h" 23#include "sftp.h" 24#include "ssh.h" 25 26#include <guacamole/client.h> 27#include <guacamole/stream.h> 28#include <guacamole/user.h> 29 30int guac_sftp_file_handler(guac_user* user, guac_stream* stream, 31 char* mimetype, char* filename) { 32 33 guac_client* client = user->client; 34 guac_ssh_client* ssh_client = (guac_ssh_client*) client->data; 35 guac_common_ssh_sftp_filesystem* filesystem = ssh_client->sftp_filesystem; 36 37 /* Handle file upload */ 38 return guac_common_ssh_sftp_handle_file_stream(filesystem, user, stream, 39 mimetype, filename); 40 41} 42 43/** 44 * Callback invoked on the current connection owner (if any) when a file 45 * download is being initiated through the terminal. 46 * 47 * @param owner 48 * The guac_user that is the owner of the connection, or NULL if the 49 * connection owner has left. 50 * 51 * @param data 52 * The filename of the file that should be downloaded. 53 * 54 * @return 55 * The stream allocated for the file download, or NULL if no stream could 56 * be allocated. 57 */ 58static void* guac_sftp_download_to_owner(guac_user* owner, void* data) { 59 60 /* Do not bother attempting the download if the owner has left */ 61 if (owner == NULL) 62 return NULL; 63 64 guac_client* client = owner->client; 65 guac_ssh_client* ssh_client = (guac_ssh_client*) client->data; 66 guac_common_ssh_sftp_filesystem* filesystem = ssh_client->sftp_filesystem; 67 68 /* Ignore download if filesystem has been unloaded */ 69 if (filesystem == NULL) 70 return NULL; 71 72 char* filename = (char*) data; 73 74 /* Initiate download of requested file */ 75 return guac_common_ssh_sftp_download_file(filesystem, owner, filename); 76 77} 78 79guac_stream* guac_sftp_download_file(guac_client* client, char* filename) { 80 81 /* Initiate download to the owner of the connection */ 82 return (guac_stream*) guac_client_for_owner(client, 83 guac_sftp_download_to_owner, filename); 84 85} 86 87void guac_sftp_set_upload_path(guac_client* client, char* path) { 88 89 guac_ssh_client* ssh_client = (guac_ssh_client*) client->data; 90 guac_common_ssh_sftp_filesystem* filesystem = ssh_client->sftp_filesystem; 91 92 /* Set upload path as specified */ 93 guac_common_ssh_sftp_set_upload_path(filesystem, path); 94 95} 96