New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDEV-30432: Refactor connect to use libcurl instead of cpprestsdk/curl #2996
base: 11.4
Are you sure you want to change the base?
Conversation
| /***********************************************************************/ | ||
| /* WriteMemoryCallback: Curl callback function */ | ||
| /***********************************************************************/ | ||
| static size_t WriteMemoryCallback(void *contents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default function writes to a file. Couldn't CURLOPT_WRITEDATA be used to set the FILE* pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried this as the first approach in first testing, but the data returned in file were cut, since size cannot be known in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sounds odd. Most web requests that curl would be programmed to do won't know the file size in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked with this:
diff --git a/storage/connect/tabrest.cpp b/storage/connect/tabrest.cpp
index 7413f6029b9..f976773f9a0 100644
--- a/storage/connect/tabrest.cpp
+++ b/storage/connect/tabrest.cpp
@@ -277,14 +277,11 @@ int RESTDEF::curl_run(PGLOBAL g)
struct MemoryStruct chunk;
chunk.memory = (char *)malloc(1);
chunk.size = 0;
+ FILE *f= fopen(Fn, "wb");
if ((curl_res= curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf)) !=
CURLE_OK ||
- (curl_res= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
- WriteMemoryCallback)) !=
- CURLE_OK ||
- (curl_res= curl_easy_setopt(curl, CURLOPT_WRITEDATA,
- (void *)&chunk)) !=
+ (curl_res= curl_easy_setopt(curl, CURLOPT_WRITEDATA, f)) !=
CURLE_OK ||
(curl_res = curl_easy_setopt(curl, CURLOPT_URL, buf)) != CURLE_OK ||
(curl_res = curl_easy_perform(curl)) != CURLE_OK ||
@@ -303,8 +300,6 @@ int RESTDEF::curl_run(PGLOBAL g)
}
}
curl_easy_cleanup(curl);
- FILE *f= fopen(Fn, "wb");
- fprintf(f, "%s", chunk.memory);
fclose(f);
free(chunk.memory);
bool is_error = http_code < 200 || http_code >= 300;
- https://curl.se/libcurl/c/CURLOPT_WRITEDATA.html says libcurl DLL must have a WRITEFUNCTION.
- BB currently doesn't have/detect libcurl on amd-windows. MDBF-644
- Internally in curl,
fwriteis used directly as the CURLOPT_WRITEFUNCTION. Unsure if that will directly work on Windows.
| curl_errbuf[0] = '\0'; | ||
| if (Uri) | ||
| { | ||
| if (*Uri == '/' || Http[strlen(Http) - 1] == '/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really odd. What's it doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inherited from old code, about parsing the argument from table options.
cac2d30
to
bed924a
Compare
|
before I forget - need to revert #2466 as part of this. |
bed924a
to
afd313a
Compare
- Remove GetRest occurance (cpprestsdk references) - Drop execv(curl) references - Link to libcurl (Unix/Windows) - Use IMPORTED target, so that INCLUDE_DIRECTORIES be called implicity - Add libcurl feature to ConnectSE to issue HTPP requests - This patch closes MDEV-26727 (tested with Docker) - Reviewer: <>
afd313a
to
3ed2341
Compare
Check linkage
Check linkage on Windows
Check without libcurl
Remove the library and check the patch
Install DB and run server locally ✔️
$ sudo apt remove libcurl4-openssl-dev $ cmake --build . --target connect [ 0%] Built target uca-dump [ 8%] Built target mysqlservices [ 8%] Built target GenUnicodeDataSource [ 58%] Built target mysys [ 75%] Built target strings [ 75%] Built target dbug [ 75%] Built target comp_err [ 75%] Built target GenError make[3]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libcurl.so', needed by 'storage/connect/ha_connect.so'. Stop. make[3]: *** Waiting for unfinished jobs.... [ 75%] Building CXX object storage/connect/CMakeFiles/connect.dir/tabrest.cpp.o /home/anel/GitHub/mariadb/server/src/connect-curl-11.4/storage/connect/tabrest.cpp:39:10: fatal error: curl/curl.h: No such file or directory 39 | #include | ^~~~~~~~~~~~~ compilation terminated.Check in container
Check container from CLI
Basing the PR against the correct MariaDB version
PR quality check