Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,20 @@ AdvSceneSwitcher.action.websocket.entry.sceneSwitcher.request="Send{{api}}of typ
AdvSceneSwitcher.action.websocket.entry.sceneSwitcher.event="Send{{api}}of type{{type}}to connected clients"
AdvSceneSwitcher.action.websocket.entry.generic="Send{{api}}via{{connection}}"
AdvSceneSwitcher.action.http="HTTP"
AdvSceneSwitcher.action.http.setHeaders="Set headers"
AdvSceneSwitcher.action.http.headers="Headers:"
AdvSceneSwitcher.action.http.addHeader="Add header"
AdvSceneSwitcher.action.http.type.get="GET"
AdvSceneSwitcher.action.http.type.post="POST"
AdvSceneSwitcher.action.http.type.put="PUT"
AdvSceneSwitcher.action.http.type.patch="PATCH"
AdvSceneSwitcher.action.http.type.delete="DELETE"
AdvSceneSwitcher.action.http.type.head="HEAD"
AdvSceneSwitcher.action.http.entry.line1="Send{{method}}to{{url}}"
AdvSceneSwitcher.action.http.entry.line2="Timeout:{{timeout}}seconds"
AdvSceneSwitcher.action.http.entry.line3="Max retries:{{count}}each{{delay}}seconds"
AdvSceneSwitcher.action.http.requestBody.placeholder="Enter request body"
AdvSceneSwitcher.action.http.setHeaders="Set headers"
AdvSceneSwitcher.action.http.headers="Headers:"
AdvSceneSwitcher.action.http.addHeader="Add header"
AdvSceneSwitcher.action.http.errorForBadStatusCode.label="Count bad status codes (4xx, 5xx) as errors"
AdvSceneSwitcher.action.variable="Variable"
AdvSceneSwitcher.action.variable.type.set="Set to fixed value"
AdvSceneSwitcher.action.variable.type.append="Append"
Expand Down Expand Up @@ -1605,6 +1612,25 @@ AdvSceneSwitcher.tempVar.streaming.keyframeInterval.description="Stream keyframe
AdvSceneSwitcher.tempVar.streaming.durationSeconds="Stream duration"
AdvSceneSwitcher.tempVar.streaming.durationSeconds.description="Seconds passed since the stream was started.\nThis value will be zero if the stream is stopped."

AdvSceneSwitcher.tempVar.http.redirects.count="Redirect count"
AdvSceneSwitcher.tempVar.http.redirects.count.description="Number of redirects until final URL got reached."
AdvSceneSwitcher.tempVar.http.response.body="Response body"
AdvSceneSwitcher.tempVar.http.response.body.description="Unparsed response body received in response."
AdvSceneSwitcher.tempVar.http.response.statusCode="Response status code"
AdvSceneSwitcher.tempVar.http.response.statusCode.description="HTTP status code received in response."
AdvSceneSwitcher.tempVar.http.response.header.contentType="Response Content-Type header"
AdvSceneSwitcher.tempVar.http.response.header.contentType.description="Content-Type header received in response."
AdvSceneSwitcher.tempVar.http.response.header.retryAfter="Response Retry-After time"
AdvSceneSwitcher.tempVar.http.response.header.retryAfter.description="Time from Retry-After header received in response, in seconds."
AdvSceneSwitcher.tempVar.http.response.headers="Response headers"
AdvSceneSwitcher.tempVar.http.response.headers.description="All headers received in response."
AdvSceneSwitcher.tempVar.http.transfer.speed.download.average="Average download speed"
AdvSceneSwitcher.tempVar.http.transfer.speed.download.average.description="Average download speed of entire transfer, in Bps."
AdvSceneSwitcher.tempVar.http.transfer.speed.upload.average="Average upload speed"
AdvSceneSwitcher.tempVar.http.transfer.speed.upload.average.description="Average upload speed of entire transfer, in Bps."
AdvSceneSwitcher.tempVar.http.transfer.time.total="Total transfer time"
AdvSceneSwitcher.tempVar.http.transfer.time.total.description="Total time to receive a response, in seconds."

AdvSceneSwitcher.selectScene="--select scene--"
AdvSceneSwitcher.selectPreviousScene="Previous Scene"
AdvSceneSwitcher.selectCurrentScene="Current Scene"
Expand Down
21 changes: 18 additions & 3 deletions lib/utils/curl-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ curl_slist *CurlHelper::SlistAppend(curl_slist *list, const char *string)
if (!curl._initialized) {
return nullptr;
}

return curl._slistAppend(list, string);
}

Expand All @@ -60,9 +61,20 @@ CURLcode CurlHelper::Perform()
if (!curl._initialized) {
return CURLE_FAILED_INIT;
}

return curl._perform(curl._curl);
}

void CurlHelper::Reset()
{
auto &curl = GetInstance();
if (!curl._initialized) {
return;
}

curl._reset(curl._curl);
}

char *CurlHelper::GetError(CURLcode code)
{
auto &curl = GetInstance();
Expand Down Expand Up @@ -113,21 +125,24 @@ bool CurlHelper::LoadLib()
}
}
}

blog(LOG_WARNING, "[adv-ss] can't find the curl library");
return false;
}

bool CurlHelper::Resolve()
{
_init = (initFunction)_lib->resolve("curl_easy_init");
_setopt = (setOptFunction)_lib->resolve("curl_easy_setopt");
_setOpt = (setOptFunction)_lib->resolve("curl_easy_setopt");
_slistAppend = (slistAppendFunction)_lib->resolve("curl_slist_append");
_perform = (performFunction)_lib->resolve("curl_easy_perform");
_cleanup = (cleanupFunction)_lib->resolve("curl_easy_cleanup");
_reset = (resetFunction)_lib->resolve("curl_easy_reset");
_error = (errorFunction)_lib->resolve("curl_easy_strerror");
_getInfo = (getInfoFunction)_lib->resolve("curl_easy_getinfo");

if (_init && _setopt && _slistAppend && _perform && _cleanup &&
_error) {
if (_init && _setOpt && _slistAppend && _perform && _cleanup &&
_reset && _error && _getInfo) {
blog(LOG_INFO, "[adv-ss] curl loaded successfully");
return true;
}
Expand Down
29 changes: 24 additions & 5 deletions lib/utils/curl-helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class CurlHelper {
EXPORT static struct curl_slist *SlistAppend(struct curl_slist *list,
const char *string);
EXPORT static CURLcode Perform();
EXPORT static void Reset();
EXPORT static char *GetError(CURLcode code);
template<typename... Args> static CURLcode GetInfo(CURLINFO, Args...);

private:
CurlHelper();
Expand All @@ -28,22 +30,27 @@ class CurlHelper {
struct curl_slist *list, const char *string);
typedef CURLcode (*performFunction)(CURL *);
typedef void (*cleanupFunction)(CURL *);
typedef void (*resetFunction)(CURL *);
typedef char *(*errorFunction)(CURLcode);
typedef CURLcode (*getInfoFunction)(CURL *, CURLINFO, ...);

EXPORT static CurlHelper &GetInstance();

bool LoadLib();
bool Resolve();

CURL *_curl = nullptr;
QLibrary *_lib;
std::atomic_bool _initialized = {false};

initFunction _init = nullptr;
setOptFunction _setopt = nullptr;
setOptFunction _setOpt = nullptr;
slistAppendFunction _slistAppend = nullptr;
performFunction _perform = nullptr;
cleanupFunction _cleanup = nullptr;
resetFunction _reset = nullptr;
errorFunction _error = nullptr;
CURL *_curl = nullptr;
QLibrary *_lib;
std::atomic_bool _initialized = {false};
getInfoFunction _getInfo = nullptr;
};

template<typename... Args>
Expand All @@ -53,7 +60,19 @@ inline CURLcode CurlHelper::SetOpt(CURLoption option, Args... args)
if (!curl._initialized) {
return CURLE_FAILED_INIT;
}
return curl._setopt(curl._curl, option, args...);

return curl._setOpt(curl._curl, option, args...);
}

template<typename... Args>
inline CURLcode CurlHelper::GetInfo(CURLINFO info, Args... args)
{
auto &curl = GetInstance();
if (!curl._initialized) {
return CURLE_FAILED_INIT;
}

return curl._getInfo(curl._curl, info, args...);
}

} // namespace advss
6 changes: 6 additions & 0 deletions lib/variables/variable-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ StringVariable::operator std::string() const
return _resolvedValue;
}

QString StringVariable::toQString() const
{
Resolve();
return QString::fromStdString(_resolvedValue);
}

StringVariable::operator QVariant() const
{
return QVariant::fromValue<StringVariable>(*this);
Expand Down
1 change: 1 addition & 0 deletions lib/variables/variable-string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class StringVariable {
EXPORT StringVariable(std::string str) : _value(std::move(str)){};
EXPORT StringVariable(const char *str) : _value(str){};
EXPORT operator std::string() const;
EXPORT QString toQString() const;
EXPORT operator QVariant() const;
EXPORT void operator=(std::string);
EXPORT void operator=(const char *value);
Expand Down
Loading