aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
Diffstat (limited to 'hotline')
-rw-r--r--hotline/account.go1
-rw-r--r--hotline/client_conn.go7
-rw-r--r--hotline/file_transfer.go4
-rw-r--r--hotline/server.go10
-rw-r--r--hotline/server_test.go11
5 files changed, 21 insertions, 12 deletions
diff --git a/hotline/account.go b/hotline/account.go
index 7f770b1..526eb05 100644
--- a/hotline/account.go
+++ b/hotline/account.go
@@ -15,6 +15,7 @@ type Account struct {
Name string `yaml:"Name"`
Password string `yaml:"Password"`
Access AccessBitmap `yaml:"Access,flow"`
+ FileRoot string `yaml:"FileRoot"`
readOffset int // Internal offset to track read progress
}
diff --git a/hotline/client_conn.go b/hotline/client_conn.go
index 060a2b9..d324591 100644
--- a/hotline/client_conn.go
+++ b/hotline/client_conn.go
@@ -42,6 +42,13 @@ type ClientConn struct {
mu sync.RWMutex
}
+func (cc *ClientConn) FileRoot() string {
+ if cc.Account.FileRoot != "" {
+ return cc.Account.FileRoot
+ }
+ return cc.Server.Config.FileRoot
+}
+
type ClientFileTransferMgr struct {
transfers map[FileTransferType]map[FileTransferID]*FileTransfer
diff --git a/hotline/file_transfer.go b/hotline/file_transfer.go
index 806466b..12725db 100644
--- a/hotline/file_transfer.go
+++ b/hotline/file_transfer.go
@@ -87,6 +87,7 @@ func (ftm *MemFileTransferMgr) Delete(id FileTransferID) {
}
type FileTransfer struct {
+ FileRoot string
FileName []byte
FilePath []byte
RefNum [4]byte
@@ -116,9 +117,10 @@ func (wc *WriteCounter) Write(p []byte) (int, error) {
return n, nil
}
-func (cc *ClientConn) NewFileTransfer(transferType FileTransferType, fileName, filePath, size []byte) *FileTransfer {
+func (cc *ClientConn) NewFileTransfer(transferType FileTransferType, fileroot string, fileName, filePath, size []byte) *FileTransfer {
ft := &FileTransfer{
FileName: fileName,
+ FileRoot: fileroot,
FilePath: filePath,
Type: transferType,
TransferSize: size,
diff --git a/hotline/server.go b/hotline/server.go
index 04ac8c7..c4d8f7f 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -526,7 +526,7 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
"Name", string(fileTransfer.ClientConn.UserName),
)
- fullPath, err := ReadPath(s.Config.FileRoot, fileTransfer.FilePath, fileTransfer.FileName)
+ fullPath, err := ReadPath(fileTransfer.FileRoot, fileTransfer.FilePath, fileTransfer.FileName)
if err != nil {
return err
}
@@ -534,7 +534,7 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
switch fileTransfer.Type {
case BannerDownload:
if _, err := io.Copy(rwc, bytes.NewBuffer(s.Banner)); err != nil {
- return fmt.Errorf("error sending Banner: %w", err)
+ return fmt.Errorf("banner download: %w", err)
}
case FileDownload:
s.Stats.Increment(StatDownloadCounter, StatDownloadsInProgress)
@@ -555,7 +555,7 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
err = UploadHandler(rwc, fullPath, fileTransfer, s.FS, rLogger, s.Config.PreserveResourceForks)
if err != nil {
- return fmt.Errorf("file upload error: %w", err)
+ return fmt.Errorf("file upload: %w", err)
}
case FolderDownload:
@@ -566,7 +566,7 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
err = DownloadFolderHandler(rwc, fullPath, fileTransfer, s.FS, rLogger, s.Config.PreserveResourceForks)
if err != nil {
- return fmt.Errorf("file upload error: %w", err)
+ return fmt.Errorf("folder download: %w", err)
}
case FolderUpload:
@@ -584,7 +584,7 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
err = UploadFolderHandler(rwc, fullPath, fileTransfer, s.FS, rLogger, s.Config.PreserveResourceForks)
if err != nil {
- return fmt.Errorf("file upload error: %w", err)
+ return fmt.Errorf("folder upload: %w", err)
}
}
return nil
diff --git a/hotline/server_test.go b/hotline/server_test.go
index c3d38da..d0e2372 100644
--- a/hotline/server_test.go
+++ b/hotline/server_test.go
@@ -99,12 +99,7 @@ func TestServer_handleFileTransfer(t *testing.T) {
{
name: "file download",
fields: fields{
- FS: &OSFileStore{},
- Config: Config{
- FileRoot: func() string {
- path, _ := os.Getwd()
- return path + "/test/config/Files"
- }()},
+ FS: &OSFileStore{},
Logger: NewTestLogger(),
Stats: NewStats(),
FileTransferMgr: &MemFileTransferMgr{
@@ -114,6 +109,10 @@ func TestServer_handleFileTransfer(t *testing.T) {
Type: FileDownload,
FileName: []byte("testfile-8b"),
FilePath: []byte{},
+ FileRoot: func() string {
+ path, _ := os.Getwd()
+ return path + "/test/config/Files"
+ }(),
ClientConn: &ClientConn{
Account: &Account{
Login: "foo",