summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOleg Morozenkov <m@oleg.rocks>2019-12-05 01:06:02 +0300
committerOleg Morozenkov <m@oleg.rocks>2019-12-05 01:06:02 +0300
commit2b5baa24597778d8e9f5d93c30a6f6440ef90971 (patch)
tree589202ffbaecb0ff2176575688e30cf18b317a61 /src
parente1031f20f9139a554c3e4cf70585ae0dcea1bcda (diff)
parent76f36598570a13862471175cbfdbfb9dec4139d2 (diff)
Merge branch 'master' into nitanmarcel/api_update_pr
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp7
-rw-r--r--src/TgTypeParser.cpp3
-rw-r--r--src/net/CurlHttpClient.cpp32
3 files changed, 20 insertions, 22 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index ee8f36f..19681f7 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -336,12 +336,11 @@ bool Api::createNewStickerSet(int32_t userId, const string& name, const string&
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
-bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
+bool Api::addStickerToSet(int32_t userId, const string& name, const boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
args.reserve(6);
args.emplace_back("user_id", userId);
args.emplace_back("name", name);
- args.emplace_back("title", title);
if (pngSticker.which() == 0 /* InputFile::Ptr */) {
auto file = boost::get<InputFile::Ptr>(pngSticker);
args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName);
@@ -363,11 +362,11 @@ bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) cons
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
-bool Api::deleteStickerPositionInSet(const string& sticker) const {
+bool Api::deleteStickerFromSet(const string& sticker) const {
vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("sticker", sticker);
- return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
+ return sendRequest("deleteStickerFromSet", args).get<bool>("", false);
}
Message::Ptr Api::sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const boost::variant<InputFile::Ptr, std::string> thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 0a098f0..999dbc1 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -1811,12 +1811,13 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::
}
string result;
result += '{';
+ if(object->pay)
+ appendToJson(result, "pay", object->pay);
appendToJson(result, "text", object->text);
appendToJson(result, "url", object->url);
appendToJson(result, "callback_data", object->callbackData);
appendToJson(result, "switch_inline_query", object->switchInlineQuery);
appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat);
- appendToJson(result, "pay", object->pay);
removeLastComma(result);
result += '}';
return result;
diff --git a/src/net/CurlHttpClient.cpp b/src/net/CurlHttpClient.cpp
index 932fd68..8b1aec4 100644
--- a/src/net/CurlHttpClient.cpp
+++ b/src/net/CurlHttpClient.cpp
@@ -37,10 +37,8 @@ CurlHttpClient::~CurlHttpClient() {
}
static size_t curlWriteString(char* ptr, size_t size, size_t nmemb, void* userdata) {
- std::string &s = *(std::string *)userdata;
- auto read = size * nmemb;
- s.append(ptr, ptr + read);
- return read;
+ static_cast<std::string *>(userdata)->append(ptr, size * nmemb);
+ return size * nmemb;
};
std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpReqArg>& args) const {
@@ -56,18 +54,21 @@ std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpRe
headers = curl_slist_append(headers, "Connection: close");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- std::string data;
- std::vector<char*> escaped;
+ curl_mime *mime;
+ curl_mimepart *part;
+ mime = curl_mime_init(curl);
if (!args.empty()) {
for (const HttpReqArg& a : args) {
- escaped.push_back(curl_easy_escape(curl, a.name.c_str(), a.name.size()));
- data += escaped.back() + std::string("=");
- escaped.push_back(curl_easy_escape(curl, a.value.c_str(), a.value.size()));
- data += escaped.back() + std::string("&");
+ part = curl_mime_addpart(mime);
+
+ curl_mime_data(part, a.value.c_str(), a.value.size());
+ curl_mime_type(part, a.mimeType.c_str());
+ curl_mime_name(part, a.name.c_str());
+ if (a.isFile) {
+ curl_mime_filename(part, a.fileName.c_str());
+ }
}
- data.resize(data.size() - 1);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data.size());
+ curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
}
std::string response;
@@ -77,10 +78,7 @@ std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpRe
auto res = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
-
- for (auto& e : escaped) {
- curl_free(e);
- }
+ curl_mime_free(mime);
if (res != CURLE_OK) {
throw std::runtime_error(std::string("curl error: ") + curl_easy_strerror(res));