Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / filesystem / SmbFile.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 // FileSmb.h: interface for the CSmbFile class.
24
25 //
26
27 //////////////////////////////////////////////////////////////////////
28
29
30 #include "IFile.h"
31 #include "URL.h"
32 #include "threads/CriticalSection.h"
33
34 #define NT_STATUS_CONNECTION_REFUSED long(0xC0000000 | 0x0236)
35 #define NT_STATUS_INVALID_HANDLE long(0xC0000000 | 0x0008)
36 #define NT_STATUS_ACCESS_DENIED long(0xC0000000 | 0x0022)
37 #define NT_STATUS_OBJECT_NAME_NOT_FOUND long(0xC0000000 | 0x0034)
38 #define NT_STATUS_INVALID_COMPUTER_NAME long(0xC0000000 | 0x0122)
39
40 struct _SMBCCTX;
41 typedef _SMBCCTX SMBCCTX;
42
43 class CSMB : public CCriticalSection
44 {
45 public:
46   CSMB();
47   ~CSMB();
48   void Init();
49   void Deinit();
50   void Purge();
51   void PurgeEx(const CURL& url);
52   void CheckIfIdle();
53   void SetActivityTime();
54   void AddActiveConnection();
55   void AddIdleConnection();
56   CStdString URLEncode(const CStdString &value);
57   CStdString URLEncode(const CURL &url);
58
59   DWORD ConvertUnixToNT(int error);
60 private:
61   SMBCCTX *m_context;
62   CStdString m_strLastHost;
63   CStdString m_strLastShare;
64 #ifdef TARGET_POSIX
65   int m_OpenConnections;
66   unsigned int m_IdleTimeout;
67 #endif
68 };
69
70 extern CSMB smb;
71
72 namespace XFILE
73 {
74 class CSmbFile : public IFile
75 {
76 public:
77   CSmbFile();
78   int OpenFile(const CURL &url, CStdString& strAuth);
79   virtual ~CSmbFile();
80   virtual void Close();
81   virtual int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET);
82   virtual unsigned int Read(void* lpBuf, int64_t uiBufSize);
83   virtual bool Open(const CURL& url);
84   virtual bool Exists(const CURL& url);
85   virtual int Stat(const CURL& url, struct __stat64* buffer);
86   virtual int Stat(struct __stat64* buffer);
87   virtual int Truncate(int64_t size);
88   virtual int64_t GetLength();
89   virtual int64_t GetPosition();
90   virtual int Write(const void* lpBuf, int64_t uiBufSize);
91
92   virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false);
93   virtual bool Delete(const CURL& url);
94   virtual bool Rename(const CURL& url, const CURL& urlnew);
95   virtual int  GetChunkSize() {return 1;}
96
97 protected:
98   CURL m_url;
99   bool IsValidFile(const CStdString& strFileName);
100   CStdString GetAuthenticatedPath(const CURL &url);
101   int64_t m_fileSize;
102   int m_fd;
103 };
104 }
105