fgerlits commented on code in PR #1442:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1442#discussion_r1000814275
##########
libminifi/src/utils/BaseHTTPClient.cpp:
##########
@@ -160,4 +160,118 @@ std::string URL::toString() const {
}
}
+/**
+ * Receive HTTP Response.
+ */
+size_t HTTPRequestResponse::receiveWrite(char *data, size_t size, size_t
nmemb, void *p) {
+ try {
+ if (p == nullptr) {
+ return CALLBACK_ABORT;
+ }
+ auto *callback = static_cast<HTTPReadCallback *>(p);
+ if (callback->stop) {
+ return CALLBACK_ABORT;
+ }
+ callback->write(data, (size * nmemb));
+ return (size * nmemb);
+ } catch (...) {
+ return CALLBACK_ABORT;
+ }
+}
+
+/**
+ * Callback for post, put, and patch operations
+ * @param data output buffer to write to
+ * @param size number of elements to write
+ * @param nmemb size of each element to write
+ * @param p input object to read from
+ */
+size_t HTTPRequestResponse::send_write(char *data, size_t size, size_t nmemb,
void *p) {
+ try {
+ if (p == nullptr) {
+ return CALLBACK_ABORT;
+ }
+ auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+ return callback->getDataChunk(data, size * nmemb);
+ } catch (...) {
+ return CALLBACK_ABORT;
+ }
+}
+
+int HTTPRequestResponse::seek_callback(void *p, int64_t offset, int) {
+ try {
+ if (p == nullptr) {
+ return SEEKFUNC_FAIL;
+ }
+ auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+ return callback->setPosition(offset);
+ } catch (...) {
+ return SEEKFUNC_FAIL;
+ }
+}
+
+size_t HTTPUploadByteArrayInputCallback::getDataChunk(char *data, size_t size)
{
+ if (stop) {
+ return HTTPRequestResponse::CALLBACK_ABORT;
+ }
+ size_t buffer_size = getBufferSize();
+ if (pos <= buffer_size) {
+ size_t len = buffer_size - pos;
+ if (len <= 0) {
+ return 0;
+ }
+ auto *ptr = getBuffer(pos);
+
+ if (ptr == nullptr) {
+ return 0;
+ }
+ if (len > size)
+ len = size;
+ memcpy(data, ptr, len);
+ pos += len;
+ seek(pos);
+ return len;
+ }
+ return 0;
+}
+
+size_t HTTPUploadByteArrayInputCallback::setPosition(int64_t offset) {
+ if (stop) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
+ }
+ if (getBufferSize() <= static_cast<size_t>(offset)) {
+ return HTTPRequestResponse::SEEKFUNC_FAIL;
Review Comment:
I don't know to what extent these seeks are actually used, but I agree on
both counts, i.e that it should be `<` and that it should be in a separate PR.
I think the whole `HTTPUploadCallback` thing should be cleaned up; this could
be a part of that. Should I create a Jira for this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]