Ingreso rápido:  

Forum: General Discussion

Tema: Plugin cURL
What libraries or packages can be used in a plugin to make cURL or any type of HTTPS call for JSON data? I've tried a few and always end up with "this plugin does not seem compatible". I've tried all the code that can be found in the online sources example as well. No need for auth or anything, just get some JSON data.


#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.h"



httplib::Client cli(url.c_str());
auto res = cli.Get("/");
seems to trip some sort of security measure.
 

Mensajes Mon 02 Oct 23 @ 3:27 pm
AdionPRO InfinityCTOMember since 2006
Should be fine.
Keep in mind however that if the library is dynamically loaded (ie you are using curl.dll or similar) that the plugin needs to be able to find the dll. Typically this means it would have to be in the same folder as VirtualDJ.exe
To get around this, instead of using the .lib you could load the dll manually using LoadLibrary. Especially with c++ this could become challenging to get the right functions though.

The easiest is probably to compile curl as a static library, and then link to the static library instead, so that you have no external dependencies.
 

Mensajes Mon 02 Oct 23 @ 4:25 pm
TY, Interesting... I'm not a C developer. I will have to fumble through it until I get it to work.
 

Mensajes Mon 02 Oct 23 @ 4:42 pm
AdionPRO InfinityCTOMember since 2006
 

Mensajes Mon 02 Oct 23 @ 6:04 pm
I went around in circles and just ended up using a system command command to use the OS curl. This is probably not a good idea but it works for now.
std::string getHttpDataFromLocalService(const std::string& url) {
std::string command = "curl -s " + url;
std::array<char, 128> buffer;
std::string result;

SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

HANDLE pipeRead, pipeWrite;
if (!CreatePipe(&pipeRead, &pipeWrite, &sa, 0)) {
writeToLogFile("/RequestSongs.co.log.txt", "CreatePipe() failed");
return "";
}

STARTUPINFOA startupInfo;
PROCESS_INFORMATION processInfo;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
ZeroMemory(&processInfo, sizeof(processInfo));

startupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startupInfo.wShowWindow = SW_HIDE;
startupInfo.hStdOutput = pipeWrite;
startupInfo.hStdError = pipeWrite;

if (!CreateProcessA(NULL, const_cast<char*>(command.c_str()), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo)) {
writeToLogFile("/RequestSongs.co.log.txt", "CreateProcessA() failed");
return "";
}

CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
CloseHandle(pipeWrite);

DWORD bytesRead;
while (true) {
if (!ReadFile(pipeRead, buffer.data(), static_cast<DWORD>(buffer.size()), &bytesRead, NULL) || bytesRead == 0) {
break;
}
result.append(buffer.data(), bytesRead);
}

CloseHandle(pipeRead);
return result;
}

 

Mensajes Tue 03 Oct 23 @ 6:44 am