diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/BSHA1.h | 2 | ||||
-rw-r--r-- | includes/BString.h | 10 | ||||
-rw-r--r-- | includes/CurlTask.h | 32 |
3 files changed, 38 insertions, 6 deletions
diff --git a/includes/BSHA1.h b/includes/BSHA1.h index 55710b2..b58a890 100644 --- a/includes/BSHA1.h +++ b/includes/BSHA1.h @@ -9,7 +9,7 @@ class SHA1 { public: SHA1() { reset(); } void reset() { sha1_init(&m_state); } - void update(const uint8_t* data, const size_t len) { sha1_process(&m_state, data, len); } + void update(const uint8_t * data, const size_t len) { sha1_process(&m_state, data, len); } void final(uint8_t * digest) { sha1_done(&m_state, digest); } enum { DIGEST_SIZE = 20 }; diff --git a/includes/BString.h b/includes/BString.h index a321a30..0a5fceb 100644 --- a/includes/BString.h +++ b/includes/BString.h @@ -126,6 +126,16 @@ class String : private std::string { char & operator[](ssize_t i) { if (i < 0) i = strlen() + i; return at(i); } void reserve(size_t s) { std::string::reserve(s); } + + size_t find_first_of(const String & set, size_t offset = 0) const { return std::string::find_first_of(set, offset); } + size_t find_last_of(const String & set, size_t offset = 0) const { return std::string::find_last_of(set, offset); } + size_t find_first_not_of(const String & set, size_t offset = 0) const { return std::string::find_first_not_of(set, offset); } + size_t find_last_not_of(const String & set, size_t offset = 0) const { return std::string::find_last_not_of(set, offset); } + + bool isEmpty() { return std::string::empty(); } + + using std::string::npos; + using std::string::size_type; }; }; diff --git a/includes/CurlTask.h b/includes/CurlTask.h index 41243ec..f1aba65 100644 --- a/includes/CurlTask.h +++ b/includes/CurlTask.h @@ -9,18 +9,28 @@ namespace Balau { class CurlTask : public StacklessTask { public: CurlTask(); - ~CurlTask(); + virtual ~CurlTask(); friend class TaskMan; + + static String percentEncode(const String & src); + static String percentDecode(const String & src); + static std::vector<String> tokenize(const String & str, const String & delimiters = "&", bool trimEmpty = true); + + virtual void prepareRequest() { } + protected: CURL * m_curlHandle; - void registerCurlHandle() { getTaskMan()->registerCurlHandle(this); } + void registerCurlHandle() { prepareRequest(); getTaskMan()->registerCurlHandle(this); } void unregisterCurlHandle() { getTaskMan()->unregisterCurlHandle(this); } + private: - virtual size_t writeFunction(char * ptr, size_t size, size_t nmemb) { return size * nmemb; } - virtual size_t readFunction(void * ptr, size_t size, size_t nmemb) { return CURL_READFUNC_ABORT; } + virtual size_t headerFunction(char * ptr, size_t size) { return size; } + virtual size_t writeFunction(char * ptr, size_t size) { return size; } + virtual size_t readFunction(void * ptr, size_t size) { return CURL_READFUNC_ABORT; } virtual int debugFunction(curl_infotype info, char * str, size_t str_len) { return 0; } virtual void curlDone(CURLcode result) { } + static size_t headerFunctionStatic(char * ptr, size_t size, size_t nmemb, void * userdata); static size_t writeFunctionStatic(char * ptr, size_t size, size_t nmemb, void * userdata); static size_t readFunctionStatic(void * ptr, size_t size, size_t nmemb, void * userdata); static int debugFunctionStatic(CURL * easy, curl_infotype info, char * str, size_t str_len, void * userdata); @@ -42,10 +52,22 @@ class DownloadTask : public CurlTask { virtual const char * getName() const override { return m_name.to_charp(); } virtual void Do() override; virtual void curlDone(CURLcode result) override; - virtual size_t writeFunction(char * ptr, size_t size, size_t nmemb) override { m_data += ptr; return size * nmemb; } + virtual void downloadDone() { } + virtual size_t writeFunction(char * ptr, size_t size) override { m_data += ptr; return size; } String m_name; Events::Custom m_evt; bool m_done = false; }; +class HttpDownloadTask : public DownloadTask { + public: + HttpDownloadTask(const String & url) : DownloadTask(url) { } + virtual ~HttpDownloadTask(); + void addHeader(const String & header); + virtual void prepareRequest() override; + + private: + struct curl_slist * m_headers = NULL; +}; + }; |