From 14c4e44a0a91e1ad701d4ae3c58185d25118e64e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 5 Jan 2024 15:54:03 +0300 Subject: Netlib: - NETLIBHTTPHEADER & NETLIBHTTPREQUEST obsoleted; - NETLIBHTTPREQUEST divided into MHttpRequest & MHttpResponse; - MHttpHeaders now manager headers both for MHttpRequest & MHttpResponse; --- plugins/PasteIt/src/PasteToWeb.cpp | 44 +++++++------------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) (limited to 'plugins/PasteIt') diff --git a/plugins/PasteIt/src/PasteToWeb.cpp b/plugins/PasteIt/src/PasteToWeb.cpp index 9d1ad7ac5f..5fdfc7afec 100644 --- a/plugins/PasteIt/src/PasteToWeb.cpp +++ b/plugins/PasteIt/src/PasteToWeb.cpp @@ -426,47 +426,19 @@ char *PasteToWeb::SendToWeb(char *url, std::map &heade WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, contentBytes, cbLen, nullptr, nullptr); --cbLen; - int nHeaders = 0; - for (std::map::iterator it = headers.begin(); it != headers.end(); ++it) { - ++nHeaders; - } - - NETLIBHTTPHEADER *httpHeaders = new NETLIBHTTPHEADER[nHeaders]; - - NETLIBHTTPREQUEST nlhr = { 0 }; + MHttpRequest nlhr; nlhr.requestType = REQUEST_POST; nlhr.flags = NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT | NLHPIF_HTTP11; - nlhr.szUrl = url; - nlhr.headers = httpHeaders; - nlhr.pData = contentBytes; - nlhr.dataLength = cbLen; - nHeaders = 0; - std::list mallBuf; - for (std::map::iterator it = headers.begin(); it != headers.end(); ++it) { - char *b1 = new char[it->first.length() + 1]; - char *b2 = new char[it->second.length() + 1]; - mir_strncpy(b1, it->first.c_str(), it->first.length() + 1); - mir_strncpy(b2, it->second.c_str(), it->second.length() + 1); - httpHeaders[nHeaders].szName = b1; - httpHeaders[nHeaders].szValue = b2; - mallBuf.push_back(b1); - mallBuf.push_back(b2); - ++nHeaders; - } + nlhr.m_szUrl = url; + nlhr.SetData(contentBytes, cbLen); + for (auto it : headers) + nlhr.AddHeader(it.first.c_str(), it.second.c_str()); char *resCont = nullptr; - nlhr.headersCount = nHeaders; NLHR_PTR nlhrReply(Netlib_HttpTransaction(g_hNetlibUser, &nlhr)); - if (nlhrReply != nullptr) { - if (nlhrReply->resultCode == 200) { - resCont = nlhrReply->pData; - nlhrReply->pData = 0; - } - } - - delete[] httpHeaders; - for (std::list::iterator it = mallBuf.begin(); it != mallBuf.end(); ++it) - delete *it; + if (nlhrReply != nullptr) + if (nlhrReply->resultCode == 200) + resCont = nlhrReply->body.Detach(); mir_free(contentBytes); return resCont; -- cgit v1.2.3