Implements IFile's OpenForWrite and Write methods to POST data with Content-Type set to "Application/Json"
<ClCompile Include="..\..\xbmc\filesystem\HTSPDirectory.cpp" />
<ClCompile Include="..\..\xbmc\filesystem\HTSPSession.cpp" />
<ClCompile Include="..\..\xbmc\filesystem\HTTPDirectory.cpp" />
+ <ClCompile Include="..\..\xbmc\filesystem\HTTPFile.cpp" />
<ClCompile Include="..\..\xbmc\filesystem\IDirectory.cpp" />
<ClCompile Include="..\..\xbmc\filesystem\IFile.cpp" />
<ClCompile Include="..\..\xbmc\filesystem\ImageFile.cpp" />
<ClInclude Include="..\..\xbmc\dialogs\GUIDialogKeyboardGeneric.h" />
<ClInclude Include="..\..\xbmc\DbUrl.h" />
<ClInclude Include="..\..\xbmc\dialogs\GUIDialogMediaFilter.h" />
+ <ClInclude Include="..\..\xbmc\filesystem\HTTPFile.h" />
<ClInclude Include="..\..\xbmc\filesystem\ImageFile.h" />
<ClInclude Include="..\..\xbmc\filesystem\VideoDatabaseDirectory\DirectoryNodeTags.h" />
<ClInclude Include="..\..\xbmc\filesystem\windows\WINFileSMB.h" />
<ClCompile Include="..\..\xbmc\interfaces\json-rpc\PVROperations.cpp">
<Filter>interfaces\json-rpc</Filter>
</ClCompile>
+ <ClCompile Include="..\..\xbmc\filesystem\HTTPFile.cpp">
+ <Filter>filesystem</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
<ClInclude Include="..\..\xbmc\interfaces\json-rpc\PVROperations.h">
<Filter>interfaces\json-rpc</Filter>
</ClInclude>
+ <ClInclude Include="..\..\xbmc\filesystem\HTTPFile.h">
+ <Filter>filesystem</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
m_bufferSize = 32768;
m_binary = true;
m_postdata = "";
+ m_postdataset = false;
m_username = "";
m_password = "";
m_httpauth = "";
m_state = new CReadState();
m_skipshout = false;
+ m_httpresponse = -1;
}
//Has to be called before Open()
g_curlInterface.easy_setopt(m_state->m_easyHandle, CURLOPT_URL, m_url.c_str());
g_curlInterface.easy_setopt(m_state->m_easyHandle, CURLOPT_TRANSFERTEXT, FALSE);
- // setup POST data if it exists
- if (!m_postdata.IsEmpty())
+ // setup POST data if it is set (and it may be empty)
+ if (m_postdataset)
{
g_curlInterface.easy_setopt(h, CURLOPT_POST, 1 );
g_curlInterface.easy_setopt(h, CURLOPT_POSTFIELDSIZE, m_postdata.length());
bool CCurlFile::Service(const CStdString& strURL, const CStdString& strPostData, CStdString& strHTML)
{
m_postdata = strPostData;
+ m_postdataset = true;
if (Open(strURL))
{
if (ReadData(strHTML))
SetCommonOptions(m_state);
SetRequestHeaders(m_state);
- long response = m_state->Connect(m_bufferSize);
- if( response < 0 || response >= 400)
+ m_httpresponse = m_state->Connect(m_bufferSize);
+ if( m_httpresponse < 0 || m_httpresponse >= 400)
return false;
SetCorrectHeaders(m_state);
void SetPostData(CStdString postdata) { m_postdata = postdata; }
void SetReferer(CStdString referer) { m_referer = referer; }
void SetCookie(CStdString cookie) { m_cookie = cookie; }
- void SetMimeType(CStdString mimetype) { SetRequestHeader("Content-Type", m_mimetype); }
+ void SetMimeType(CStdString mimetype) { SetRequestHeader("Content-Type", mimetype); }
void SetRequestHeader(CStdString header, CStdString value);
void SetRequestHeader(CStdString header, long value);
void SetCorrectHeaders(CReadState* state);
bool Service(const CStdString& strURL, const CStdString& strPostData, CStdString& strHTML);
- private:
+ protected:
CReadState* m_state;
unsigned int m_bufferSize;
CStdString m_postdata;
CStdString m_referer;
CStdString m_cookie;
- CStdString m_mimetype;
CStdString m_username;
CStdString m_password;
CStdString m_httpauth;
bool m_seekable;
bool m_multisession;
bool m_skipshout;
+ bool m_postdataset;
CRingBuffer m_buffer; // our ringhold buffer
char * m_overflowBuffer; // in the rare case we would overflow the above buffer
typedef std::map<CStdString, CStdString> MAPHTTPHEADERS;
MAPHTTPHEADERS m_requestheaders;
+
+ long m_httpresponse;
};
}
#include "FileFactory.h"
#include "HDFile.h"
#include "CurlFile.h"
+#include "HTTPFile.h"
#include "ShoutcastFile.h"
#include "LastFMFile.h"
#include "FileReaderFile.h"
if( g_application.getNetwork().IsAvailable() )
{
- if (strProtocol == "http"
- || strProtocol == "https"
- || strProtocol == "dav"
+ if (strProtocol == "dav"
|| strProtocol == "davs"
|| strProtocol == "ftp"
|| strProtocol == "ftps"
|| strProtocol == "rss") return new CCurlFile();
+ else if (strProtocol == "http" || strProtocol == "https") return new CHTTPFile();
#ifdef HAS_FILESYSTEM_SFTP
else if (strProtocol == "sftp" || strProtocol == "ssh") return new CSFTPFile();
#endif
--- /dev/null
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "HTTPFile.h"
+
+using namespace XFILE;
+
+CHTTPFile::CHTTPFile(void)
+{
+ m_openedforwrite = false;
+}
+
+
+CHTTPFile::~CHTTPFile(void)
+{
+}
+
+bool CHTTPFile::OpenForWrite(const CURL& url, bool bOverWrite)
+{
+ // real Open is delayed until we receive the POST data
+ m_urlforwrite = url;
+ m_openedforwrite = true;
+ return true;
+}
+
+int CHTTPFile::Write(const void* lpBuf, int64_t uiBufSize)
+{
+ // Although we can not verify much, try to catch errors where we can
+ if (!m_openedforwrite)
+ return -1;
+
+ CStdString myPostData((char*) lpBuf);
+ if (myPostData.length() != uiBufSize)
+ return -1;
+
+ // If we get here, we (most likely) satisfied the pre-conditions that we used OpenForWrite and passed a string as postdata
+ // we mimic 'post(..)' but do not read any data
+ m_postdata = myPostData;
+ m_postdataset = true;
+ m_openedforwrite = false;
+ SetMimeType("application/json");
+ if (!Open(m_urlforwrite))
+ return -1;
+
+ // Finally (and this is a clumsy hack) return the http response code
+ return (int) m_httpresponse;
+}
+
--- /dev/null
+#pragma once
+/*
+* Copyright (C) 2005-2012 Team XBMC
+* http://www.xbmc.org
+*
+* This Program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2, or (at your option)
+* any later version.
+*
+* This Program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with XBMC; see the file COPYING. If not, see
+* <http://www.gnu.org/licenses/>.
+*
+*/
+
+#include "CurlFile.h"
+#include "URL.h"
+
+namespace XFILE
+{
+ class CHTTPFile : public CCurlFile
+ {
+ public:
+ CHTTPFile(void);
+ virtual ~CHTTPFile(void);
+ virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false);
+ virtual int Write(const void* lpBuf, int64_t uiBufSize);
+ private:
+ bool m_openedforwrite;
+ CURL m_urlforwrite;
+ };
+}
SRCS += HTSPDirectory.cpp
SRCS += HTSPSession.cpp
SRCS += HTTPDirectory.cpp
+SRCS += HTTPFile.cpp
SRCS += IDirectory.cpp
SRCS += IFile.cpp
SRCS += ImageFile.cpp