diff --git a/src/curlrequester.cpp b/src/curlrequester.cpp index 86ce623..3a0a280 100644 --- a/src/curlrequester.cpp +++ b/src/curlrequester.cpp @@ -8,7 +8,7 @@ static size_t trampoline(char* dest, size_t size, size_t nmemb, void* userp) return cid->requestWrite(dest, size*nmemb); } -CurlRequester::CurlRequester(QUrl addr, Role role) +CurlRequester::CurlRequester(QUrl addr, Role role, Bytestream* singleData) : _addr(addr), _canWrite(1), _canRead(), _reading(false), _done(false), _dest(nullptr), _size(0), _offset(0), _curl(curl_easy_init()) { @@ -36,7 +36,15 @@ CurlRequester::CurlRequester(QUrl addr, Role role) curl_easy_setopt(_curl, CURLOPT_READDATA, this); _opts = curl_slist_append(_opts, "Expect:"); - _opts = curl_slist_append(_opts, "Transfer-Encoding: chunked"); + if(singleData != nullptr) + { + curl_easy_setopt(_curl, CURLOPT_POSTFIELDSIZE, singleData->size()); + write((char*)(singleData->raw()), singleData->size()); + } + else + { + _opts = curl_slist_append(_opts, "Transfer-Encoding: chunked"); + } _opts = curl_slist_append(_opts, "Content-Type: application/ipp"); _opts = curl_slist_append(_opts, "Accept-Encoding: identity"); break; @@ -121,7 +129,7 @@ size_t CurlRequester::requestWrite(char* dest, size_t size) if(!_reading) { _canRead.acquire(); - if(_done) // Can only have been set by write() - only relevant to check if strating to write + if(_done) // Can only have been set by await() - only relevant to check if strating to write { return 0; } diff --git a/src/curlrequester.h b/src/curlrequester.h index 705ae1c..bf8679a 100644 --- a/src/curlrequester.h +++ b/src/curlrequester.h @@ -19,7 +19,7 @@ public: HttpGetRequest }; - CurlRequester(QUrl addr, Role role = IppRequest); + CurlRequester(QUrl addr, Role role = IppRequest, Bytestream* = nullptr); ~CurlRequester(); CURLcode await(Bytestream* = nullptr); diff --git a/src/printerworker.cpp b/src/printerworker.cpp index ea9926b..6eb2106 100644 --- a/src/printerworker.cpp +++ b/src/printerworker.cpp @@ -38,29 +38,25 @@ void PrinterWorker::getImage(QUrl url) void PrinterWorker::getPrinterAttributes(Bytestream msg) { - CurlRequester cr(_printer->httpUrl()); - cr.write((char*)msg.raw(), msg.size()); + CurlRequester cr(_printer->httpUrl(), CurlRequester::IppRequest, &msg); awaitResult(cr, "getPrinterAttributesFinished"); } void PrinterWorker::getJobs(Bytestream msg) { - CurlRequester cr(_printer->httpUrl()); - cr.write((char*)msg.raw(), msg.size()); + CurlRequester cr(_printer->httpUrl(), CurlRequester::IppRequest, &msg); awaitResult(cr, "getJobsRequestFinished"); } void PrinterWorker::cancelJob(Bytestream msg) { - CurlRequester cr(_printer->httpUrl()); - cr.write((char*)msg.raw(), msg.size()); + CurlRequester cr(_printer->httpUrl(), CurlRequester::IppRequest, &msg); awaitResult(cr, "cancelJobFinished"); } void PrinterWorker::identify(Bytestream msg) { - CurlRequester cr(_printer->httpUrl()); - cr.write((char*)msg.raw(), msg.size()); + CurlRequester cr(_printer->httpUrl(), CurlRequester::IppRequest, &msg); awaitResult(cr, "identifyFinished"); }