| 1 |
/* |
| 2 |
* originally taken from pvr.zattoo |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "kodi/Filesystem.h" |
| 6 |
|
| 7 |
#include <map> |
| 8 |
#include <string> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
struct Cookie |
| 12 |
{ |
| 13 |
std::string host; |
| 14 |
std::string name; |
| 15 |
std::string value; |
| 16 |
}; |
| 17 |
|
| 18 |
class Curl |
| 19 |
{ |
| 20 |
public: |
| 21 |
Curl(); |
| 22 |
virtual ~Curl(); |
| 23 |
std::string Delete(const std::string& url, const std::string& postData, int& statusCode); |
| 24 |
std::string Get(const std::string& url, int& statusCode); |
| 25 |
std::string Post(const std::string& url, const std::string& postData, int& statusCode); |
| 26 |
std::string Put(const std::string& url, const std::string& postData, int& statusCode); |
| 27 |
void AddHeader(const std::string& name, const std::string& value); |
| 28 |
void AddOption(const std::string& name, const std::string& value); |
| 29 |
void ResetHeaders(); |
| 30 |
virtual std::string GetCookie(const std::string& name); |
| 31 |
void SetCookie(const std::string& host, const std::string& name, const std::string& value); |
| 32 |
const std::string& GetLocation() const { return m_location; } |
| 33 |
void SetRedirectLimit(int limit) { m_redirectLimit = limit; } |
| 34 |
|
| 35 |
private: |
| 36 |
kodi::vfs::CFile* PrepareRequest(const std::string& action, |
| 37 |
const std::string& url, |
| 38 |
const std::string& postData); |
| 39 |
void ParseCookies(kodi::vfs::CFile* file, const std::string& host); |
| 40 |
std::string Request(const std::string& action, |
| 41 |
const std::string& url, |
| 42 |
const std::string& postData, |
| 43 |
int& statusCode); |
| 44 |
std::string ParseHostname(const std::string& url); |
| 45 |
std::string Base64Encode(const std::string& str, bool urlEncode); |
| 46 |
std::map<std::string, std::string> m_headers; |
| 47 |
std::map<std::string, std::string> m_options; |
| 48 |
std::vector<Cookie> m_cookies; |
| 49 |
std::string m_location; |
| 50 |
int m_redirectLimit = 8; |
| 51 |
}; |