init http framework
This commit is contained in:
35
include/drive.h
Normal file
35
include/drive.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
enum drive_type {
|
||||
dt_alipan,
|
||||
dt_filebrowser,
|
||||
};
|
||||
|
||||
/// @brief file entry
|
||||
struct dItem {
|
||||
std::string id;
|
||||
std::string name;
|
||||
bool folder;
|
||||
};
|
||||
|
||||
class drive {
|
||||
public:
|
||||
virtual ~drive() {}
|
||||
typedef std::shared_ptr<drive> ref;
|
||||
typedef void (*fnQrcode)(const std::string&);
|
||||
|
||||
virtual int qrLogin(fnQrcode printQr) = 0;
|
||||
virtual std::vector<dItem> list(const std::string& file_id) = 0;
|
||||
virtual std::string mkdir(const std::string& parent_id, const std::string& name) = 0;
|
||||
virtual std::string upload(const std::string& parent_id, const std::string& file) = 0;
|
||||
};
|
||||
|
||||
/// @brief factory funtion
|
||||
drive::ref new_drive(drive_type type);
|
||||
|
||||
std::string hex_encode(const unsigned char* data, size_t len);
|
||||
|
||||
33
include/http.h
Normal file
33
include/http.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2023 dragonflylee
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <curl/curl.h>
|
||||
|
||||
class HTTP {
|
||||
public:
|
||||
using Form = std::unordered_map<std::string, std::string>;
|
||||
|
||||
HTTP();
|
||||
HTTP(const HTTP& other) = delete;
|
||||
~HTTP();
|
||||
|
||||
static std::string encode_form(const Form& form);
|
||||
void set_headers(const std::vector<std::string>& headers);
|
||||
int get(const std::string& url, std::ostream *out);
|
||||
std::string put(const std::string& url, std::istream *data);
|
||||
std::string post(const std::string& url, const std::string& data);
|
||||
|
||||
private:
|
||||
static size_t easy_write_cb(char* ptr, size_t size, size_t nmemb, void* userdata);
|
||||
static size_t easy_read_cb(char* ptr, size_t size, size_t nmemb, void* userdata);
|
||||
int perform(std::ostream* body);
|
||||
|
||||
CURL* easy;
|
||||
struct curl_slist* chunk;
|
||||
};
|
||||
Reference in New Issue
Block a user