xbmc
SMBFile.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 // SMBFile.h: interface for the CSMBFile class.
12 
13 //
14 
16 
17 
18 #include "URL.h"
19 #include "filesystem/IFile.h"
20 #include "threads/CriticalSection.h"
21 
22 #define NT_STATUS_CONNECTION_REFUSED long(0xC0000000 | 0x0236)
23 #define NT_STATUS_INVALID_HANDLE long(0xC0000000 | 0x0008)
24 #define NT_STATUS_ACCESS_DENIED long(0xC0000000 | 0x0022)
25 #define NT_STATUS_OBJECT_NAME_NOT_FOUND long(0xC0000000 | 0x0034)
26 #define NT_STATUS_INVALID_COMPUTER_NAME long(0xC0000000 | 0x0122)
27 
28 struct _SMBCCTX;
29 typedef _SMBCCTX SMBCCTX;
30 
31 class CSMB : public CCriticalSection
32 {
33 public:
34  CSMB();
35  ~CSMB();
36  void Init();
37  void Deinit();
38  /* Makes sense to be called after acquiring the lock */
39  bool IsSmbValid() const { return m_context != nullptr; }
40  void CheckIfIdle();
41  void SetActivityTime();
42  void AddActiveConnection();
43  void AddIdleConnection();
44  std::string URLEncode(const std::string &value);
45  std::string URLEncode(const CURL &url);
46 
47  DWORD ConvertUnixToNT(int error);
48  static CURL GetResolvedUrl(const CURL& url);
49 
50 private:
51  SMBCCTX *m_context;
52  int m_OpenConnections;
53  unsigned int m_IdleTimeout;
54  static bool IsFirstInit;
55 };
56 
57 extern CSMB smb;
58 
59 namespace XFILE
60 {
61 class CSMBFile : public IFile
62 {
63 public:
64  CSMBFile();
65  int OpenFile(const CURL &url, std::string& strAuth);
66  ~CSMBFile() override;
67  void Close() override;
68  int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET) override;
69  ssize_t Read(void* lpBuf, size_t uiBufSize) override;
70  bool Open(const CURL& url) override;
71  bool Exists(const CURL& url) override;
72  int Stat(const CURL& url, struct __stat64* buffer) override;
73  int Stat(struct __stat64* buffer) override;
74  int Truncate(int64_t size) override;
75  int64_t GetLength() override;
76  int64_t GetPosition() override;
77  ssize_t Write(const void* lpBuf, size_t uiBufSize) override;
78 
79  bool OpenForWrite(const CURL& url, bool bOverWrite = false) override;
80  bool Delete(const CURL& url) override;
81  bool Rename(const CURL& url, const CURL& urlnew) override;
82  int GetChunkSize() override { return 64*1024; }
83  int IoControl(EIoControl request, void* param) override;
84 
85 protected:
86  CURL m_url;
87  bool IsValidFile(const std::string& strFileName);
88  std::string GetAuthenticatedPath(const CURL &url);
89  int64_t m_fileSize;
90  int m_fd;
91  bool m_allowRetry;
92 };
93 }
Definition: Scraper.h:41
Definition: URL.h:21
Definition: IFile.h:42
Definition: SMBFile.h:61
Definition: SMBFile.h:31